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

当entity类被打包成独立的jar并导入到web项目中时,遇到'java.lang.IllegalArgumentException: Not an entity'错误。错误源于Hibernate无法识别entity。解决方案包括在persistence.xml中指定jar文件或列出所有entity类名。最终选择了在persistence.xml中列出所有entity类的方式,避免了更新persistence.xml和Eclipse部署问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

将 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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值