`
iliuyong
  • 浏览: 141420 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

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

    博客分类:
  • java
阅读更多

将 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

 

分享到:
评论
1 楼 endual 2013-08-23  
博主可以发个demo帮我下吗,谢谢!
我还是搞不出来,我的持久层配置没有用到 persistence.xml,直接用dataSource.
我的邮箱 chenweishaoxing@163.com

相关推荐

Global site tag (gtag.js) - Google Analytics