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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章