我在Title上收到Hibernate Exception。我发现常见的问题是实体没有在hibernate配置文件中列出。但就我而言,我在hibernate配置文件中键入了类名。
以下是我的代码片段:
@Entity
@Table(name = "JENIS", schema = "APP")
public class Jenis implements java.io.Serializable {
private int id;
private int cloudid;
private String nama_jenis;
private List<Item> items;
public Jenis() {
}
...
@OneToMany(mappedBy="jenis", cascade = CascadeType.ALL, fetch=FetchType.LAZY)
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}
@Entity
@Table(name = "ITEM", schema = "APP")
public class Item implements java.io.Serializable {
private Jenis jenis;
...
@ManyToOne
@JoinColumn(name = "JENIS")
public Jenis getJenis() {
return jenis;
}
public void setJenis(Jenis jenis) {
this.jenis = jenis;
}
...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect
</property>
<property name="connection.pool_size">5</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
....
<mapping class="com.mypackage.beans.Jenis" />
<mapping class="com.mypackage.beans.Item" />
....
</session-factory>
</hibernate-configuration>
答案 0 :(得分:0)
Hibernate想要每个表中的主键。请确保您的两个表都有@ID注释