从Hibernate 4.2升级到5.5.5后,我的继承不再起作用了。启动我的应用程序时会抛出以下错误:
ERROR AssertionFailure:33 - HHH000099:发生断言失败(这可能表示Hibernate中存在错误,但更可能是由于会话的不安全使用):org.hibernate.AssertionFailure:找不到表
BASE.ANIMAL
这里是我的课程:
cat.java
package ext;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="CAT", schema="EXT")
@Inheritance(strategy=InheritanceType.JOINED)
@PrimaryKeyJoinColumn(name="ANIMALid", referencedColumnName="id")
public class CAT extends base.ANIMAL implements Serializable {
public CAT() {
}
public String toString() {
return super.toString();
}
}
animal.java
package base;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="ANIMAL", schema="BASE")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorValue("ANIMAL")
public class ANIMAL implements Serializable {
public ANIMAL() {
}
@Column(name="id", nullable=false, unique=true, length=10)
@Id
@GeneratedValue(generator="BASE_ANIMAL_ID_GENERATOR")
@org.hibernate.annotations.GenericGenerator(name="BASE_ANIMAL_ID_GENERATOR", strategy="native", parameters={ @org.hibernate.annotations.Parameter(name="schema", value="BASE") })
private int id;
private void setId(int value) {
this.id = value;
}
public int getId() {
return id;
}
public int getORMID() {
return getId();
}
public String toString() {
return String.valueOf(getId());
}
}
识别TestClass
package ormsamples;
import org.orm.*;
public class CreateJoinedinheritanceData {
public void createTestData() throws PersistentException {
PersistentTransaction t = ext.JoinedinheritancePersistentManager.instance().getSession().beginTransaction();
try {
base.ANIMAL bASEANIMAL = base.ANIMALDAO.createANIMAL();
// Initialize the properties of the persistent object here
base.ANIMALDAO.save(bASEANIMAL);
ext.CAT eXTCAT = ext.CATDAO.createCAT();
// Initialize the properties of the persistent object here
ext.CATDAO.save(eXTCAT);
t.commit();
}
catch (Exception e) {
t.rollback();
}
}
public static void main(String[] args) {
try {
CreateJoinedinheritanceData createJoinedinheritanceData = new CreateJoinedinheritanceData();
try {
createJoinedinheritanceData.createTestData();
}
finally {
ext.JoinedinheritancePersistentManager.instance().disposePersistentManager();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
我是否错过了迁移步骤,或者最新的hibernate 5版本中是否存在错误?
期待您的建议!