JPA 异常: Caused by: org.hibernate.AnnotationException: No identifier specified for entity
程序员文章站
2022-04-12 16:28:11
...
使用JPA/HIbernate时, PO类必须使用@Id 指定一个主键标识. 如果未指定@Id标识, 则会抛出No identifier 异常. 需要注意的是, @Id 为java.persistence包下的注解, 别引成spring 包下的@Id注解了. 笔者就是引错注解导致的这个问题.
- 正确注解: import javax.persistence.Id;
- 错误注解: import org.springframework.data.annotation.Id;
异常描述
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: org.zongf.test.test.po.PersonPO
at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:266)
at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:775)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:250)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:231)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:274)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:904)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
... 39 more
上一篇: mysql 1136错误 Column count doesn't match value count at row 1
下一篇: Caused by: java.lang.NoClassDefFoundError: org/mybatis/logging/LoggerFactory
推荐阅读
-
错误org.hibernate.AnnotationException: No identifier specified for entity
-
JPA 异常: Caused by: org.hibernate.AnnotationException: No identifier specified for entity
-
Caused by: org.hibernate.AnnotationException: No identifier specified for entity
-
Caused by: org.hibernate.AnnotationException: No identifier specified for en . . . . .
-
Caused by: org.hibernate.AnnotationException: No identifier specified for entity
-
Caused by: org.hibernate.AnnotationException: No identifier specified for entity:
-
Caused by: org.hibernate.AnnotationException: No identifier specified for en . . . . .