具有不同模式的Hibernate @Inheritance(strategy = InheritanceType.JOINED)会导致错误(HHH000099)

时间:2018-05-30 15:48:29

标签: java hibernate

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

期待您的建议!

1 个答案:

答案 0 :(得分:1)

在做了一些研究后,我遇到了这个hibernate bug HHH-10490

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

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

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

一切都恢复正常。

与此post类似,也由错误作者here描述。