gpt4 book ai didi

java - 具有不同架构的 Hibernate @Inheritance(strategy=InheritanceType.JOINED) 会导致错误(HHH000099)

转载 作者:行者123 更新时间:2023-12-02 11:11:20 24 4
gpt4 key购买 nike

从 Hibernate 4.2 升级到 5.5.5 后,我的继承不再起作用。启动我的应用程序会引发以下错误:

ERROR AssertionFailure:33 - HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Table BASE.ANIMAL not found

这是我的类(class):

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());
}

}

测试类

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 版本中是否存在错误?

期待您的建议!

最佳答案

做了更多研究后,我遇到了这个 hibernate 错误 HHH-10490 .

它被拒绝,答案是使用catalog而不是schema。不幸的是没有给出进一步的解释,但如果我改变这一行

@Table(name="ANIMAL", schema="BASE")

@Table(name="ANIMAL", catalog="BASE")

一切又恢复正常了。

与此类似post ,也由 bug 作者 here 描述.

关于java - 具有不同架构的 Hibernate @Inheritance(strategy=InheritanceType.JOINED) 会导致错误(HHH000099),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50608864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com