No identifier specified for entity: com.liuyanzhao.sell.entity.ProductInfo报错解决

最近在学习 SpringBoot,刚才写了个方法,在测试的时候,报了下列错误
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.liuyanzhao.sell.entity.ProductInfo
 at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:265)
 at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211)
 at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:717)
 at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:245)
 at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222)
 at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265)
 at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
 at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
 at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
 at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
 at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
 at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
 ... 39 more
  网上查了一下,都是说没有给加主键,或者没有加 @Id 注解。 然后,事实上我都是加了的。 后来发现,原来是导错了包 @Id 所在的包导错了     导入错误的 import org.hibernate.annotations.Entity; import org.springframework.data.annotation.Id;   导入正确的后 import javax.persistence.Entity; import javax.persistence.Id;   下次导入包的时候,一定要小心呀   本文地址:https://liuyanzhao.com/6643.html

发表评论

目前评论:1