hibernate联接的子类表

lyfkaqu1  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(203)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="A" table="A">
        <!- properties ->
        <joined-subclass name="B" table="B">
            <!- properties ->
        </joined-subclass>
    </class>
</hibernate-mapping>

班级

public class A{
    //Instance variables
    public A(){

    }

    // getters and setters for instance variables
}

public class B extends A{
    // Instance variables of B
    public B(){

    }
    // Setters and getters for class B
}

我使用的是Hibernate5.0.7版本。我有上面提到的hibernateMap。b扩展了一个类(两者都不是抽象的)。当hibernate初始化时,表'a'没有创建,将引发异常。其他数据库(mysql)中有相同的表名“a”。对于简单的表,向hibernatecfg(class tag)添加“schema”解决了这个问题。但对于继承的超类和子类,这是行不通的。有什么配置我遗漏了吗?

例外情况

org.hibernate.mappingexception:无法在org.hibernate.persister.internal.persisterfactoryimpl.createentitypersister(persisterfactoryimpl)示例化persister org.hibernate.persister.entity.joinedSubassentitypersister。java:112)位于org.hibernate.persister.internal.persisterfactoryimpl.createentitypersister(persisterfactoryimpl。java:77)在org.hibernate.internal.sessionfactoryimpl.(sessionfactoryimpl。java:346)在org.hibernate.boot.internal.sessionfactorybuilderimpl.build(sessionfactorybuilderimpl。java:444)在org.hibernate.cfg.configuration.buildsessionfactory(配置。java:708)在org.hibernate.cfg.configuration.buildsessionfactory(配置。java:724)
原因:org.hibernate.assertionfailure:在org.hibernate.persister.entity.abstractentitypersister.gettableid(abstractentitypersister)中找不到表db.a。java:5107)位于org.hibernate.persister.entity.joinedSubassentityperMaster。java:433)位于sun.reflect.nativeconstructoraccessorimpl.newinstance0(本机方法)sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl。java:62)在sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl。java:45)在java.lang.reflect.constructor.newinstance(constructor。java:423)在org.hibernate.persister.internal.persisterfactoryimpl.createentitypersister(persisterfactoryimpl。java:96) ... 10多个

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题