Spring data JPA java.lang.IllegalArgumentException: Not an entity

将 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

 

你可能感兴趣的:(exception)