将 entity 单独放在一个项目中,打包成 abc.jar 放到web项目中,提示 错误
aused by: java.lang.IllegalArgumentException: Not an entity: class com.classify.model.Classify
at org.hibernate.ejb.metamodel.MetamodelImpl.entity(MetamodelImpl.java:179)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:52)
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getMetadata(JpaEntityInformationSupport.java:61)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:145)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:83)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:66)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:146)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:120)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:39)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 65 more
解决方法
参考:
https://forum.hibernate.org/viewtopic.php?f=1&t=1008811
Finally found out how to do this.. Got some help over at stackoverflow:
http://stackoverflow.com/questions/5064 ... wo-webapps
Seems there are two ways to solve it:
1) Specify the entity jar file in persistence.xml: <jar-file>common.jar</jar-file>
2) List all entities by class name in persistence.xml using <class>com.mycompany.model.Locale</class>
We ended up using the second approach. I couldn't get the first approach working when deploying with eclipse, and it would also require us to update the persistence.xml each time version numbers change (since we build with maven). Any solutions to these problems?
Anyway, so happy we finally figured this one out.
-Anders
Spring Data JPA报错:Not an entity 解决方案
当entity类被打包成独立的jar并导入到web项目中时,遇到'java.lang.IllegalArgumentException: Not an entity'错误。错误源于Hibernate无法识别entity。解决方案包括在persistence.xml中指定jar文件或列出所有entity类名。最终选择了在persistence.xml中列出所有entity类的方式,避免了更新persistence.xml和Eclipse部署问题。
2348

被折叠的 条评论
为什么被折叠?



