我的项目使用的是hibernate3和spring 2.5。现在,我使用JPA将其迁移到Spring5和hibernate5。
我有hbm.xml
用于使用休眠映射的实体。迁移后,我得到了错误:
由以下原因引起:org.hibernate.AssertionFailure:无法找到引用的对象 实体映射[com.mycompany.common.admin.Entity1]以便 处理多对一FK:com.mycompany.common.admin.Entity2
Entity2具有参考Entity1的多对一FK
applicationContext.xml中用于实体管理工厂的代码:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource">
<ref bean="myDataSource"/>
</property>
<property name="packagesToScan" value="com.mycompany"/>
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
<property name="persistenceUnitPostProcessors">
<list>
<bean
class="org.springframework.data.jpa.support.ClasspathScanningPersistenceUnitPostProcessor">
<constructor-arg index="0" value="com.mycompany" />
<property name="mappingFileNamePattern" value="classpath*:com/**/*hbm.xml" />
</bean>
</list>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
Entity2的hbm.xml如下:
<?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="com.mycompany.common.admin.Entity2" table="entity2">
<id column="id" name="ID">
<generator class="uuid"/>
</id>
<property name="name" type="string">
<column name="name"/>
</property>
<many-to-one class="com.mycompany.common.admin.Entity1" name="entity1" not-null="true"/>
</class>
</hibernate-mapping>
错误堆栈跟踪:
Caused by: org.hibernate.AssertionFailure: Unable to locate referenced entity mapping [com.mycompany.common.admin.Entity1] in order to process many-to-one FK : com.mycompany.common.admin.Entity2.entity1
at org.hibernate.boot.model.source.internal.hbm.ModelBinder$ManyToOneColumnBinder.doSecondPass(ModelBinder.java:4066)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1696)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1652)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:287)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:904)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1758)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1695)
请让我知道我在这里想念什么。