当春天加载EntityManagerFactory时,我正在使用最新的springframework disto v4.2.5.RELEASE和Hibernate v5.0.7.Final我得到以下异常
Caused by: org.hibernate.HibernateException: Not all named super-types (extends) were found : [com.sample.model.Sample]
at org.hibernate.boot.model.source.internal.hbm.EntityHierarchyBuilder.buildHierarchies(EntityHierarchyBuilder.java:76)
at org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl.<init>(HbmMetadataSourceProcessorImpl.java:66)
at org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl.<init>(HbmMetadataSourceProcessorImpl.java:40)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.<init>(MetadataBuildingProcess.java:142)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:141)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:319)
相同的代码正在使用v4.2.5.RELEASE和Hibernate v.4.3.10。
我知道Hibernate改变了v5.x中的核心元数据构建,是否需要在JPA / EntityManagerFactory / Hibernate属性的spring配置中指定它以使其与Hibernate 5.x一起使用?
@Entity
@Table(name = "tbl_sample")
public class Sample extends Auditable {
private Long id;
@ManyToOne
@JoinColumn(name = "relationA", nullable = true)
private RelationA relationA;
... etc
}
@MappedSuperClass
public abstract class Auditable extends Persistable {
//audit props
}
@MappedSuperClass
public abstract class Persistable {
//common props
}
我可以在启用跟踪日志后缩小问题范围,还有一个类正在扩展Sample Class,并使用hbm.xml映射,如下所示
<hibernate-mapping package="com.sample.model">
<joined-subclass name="BloodSample" table="tbl_blood_sample"
extends="com.sample.model.Sample">
<key column="ID" />
<property name="sampleNo" column="sampleNo"/>
etc....
</joined-subclass>
我删除这个关系的那一刻hbm它开始工作了......仍然想知道为什么它现在正在发生,而不是旧版本的hibernate。
所以我想这个问题与spring无关,但与hibernate有关。任何见解?
答案 0 :(得分:0)
我有类似的问题。 您尝试在hbm.xml文件
中对class标记而不是joined-subclass标记