2
這是我的POJO,一個簡單的學生課。Hibernate org.hibernate.MappingException for non-annotated field
org.hibernate.MappingException: Could not determine type for: java.util.List, at table: Students, for columns: [org.hibernate.mapping.Column(homework)]
這就是:
@Proxy(lazy = false)
@Entity(name = "Students")
public class Student implements Serializable {
private static final long serialVersionUID = -9182600037012718128L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private String name;
private List<Homework> homework; // <-- the problematic line
public Student(){
}
public getId(){return id;}
public setId(long id){this.id = id;}
public getName(){return name;}
public setName(String name){this.name = name;}
public getHomework(){return homework;}
public setHomework(List<Homework> homework){this.homework = homework;}
}
不幸的是,即使homework
場沒有被標註(因爲我目前不想把它映射到我的DB),我跑我的應用程序時,你得到這個異常我休眠-config.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<property name="username" value="root" />
<property name="password" value="root" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://127.0.0.1:3306/test" />
<property name="testOnBorrow" value="true" />
<property name="validationQuery" value="select 1" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.hbm2ddl.auto=update
hibernate.show.sql=true
</value>
</property>
<property name="annotatedClasses">
<list>
<value>com.test.entity.Student</value>
</list>
</property>
</bean>
任何幫助是apprec iated! 謝謝!
感謝您的快速響應...但爲什麼它映射?不應該Hibernate映射只有註釋的字段? –
@ZivLevy我更新了帖子來回答你的問題 – sanbhat
非常感謝Sanbhat!乾杯... –