No identifier specified for entity: XXXX 错误

在运行项目的时候报了下面的错误:

by: org.hibernate.AnnotationException: No identifier specified for entity: com.example1.demo1.Entity.User
    at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:266) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:731) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:249) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:861) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:888) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]

这是因为在实体的getID方法上没有加上此@Id注解,但是检查了一次确实加上了,最后的解决办法如下:

是因为id注解引错的包

错误的包路径:

import org.springframework.data.annotation.Id;
正确的包路径:
import javax.persistence.Id;

最后得以解决,小伙伴们千万别粗心大意啊



原文地址:https://www.cnblogs.com/itiande/p/9139161.html

时间: 2025-01-15 22:05:26

No identifier specified for entity: XXXX 错误的相关文章

SpringBoot2 JPA No Identifier specified for entity的解决办法

No Identifier specified for entity的错误 此类注解都在 import javax.persistence.*;包下     @Id     @GeneratedValue(strategy= GenerationType.AUTO) 原因:以上文字没写或者写错了地方,导致找不到主键. 解决办法:在数据库表对应实体(entity.java)的方法:getId()前加上该段文字. P.S.: strategy= GenerationType.AUTO中的AUTO应当

An entity cannot be annotated with both @Entity and @MappedSuperclass: com.example1.demo1.Entity.User错误

项目问SpringDataJpa项目,在运行的过程中出现的以下错误: Caused by: org.hibernate.AnnotationException: An entity cannot be annotated with both @Entity and @MappedSuperclass: com.example1.demo1.Entity.User at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.ja

org.hibernate.AnnotationException: No identifier specified for entity

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: 使用hibernate的e-r映射pojo类的时候遇到org.hibernate.AnnotationException: No identifier specified for entity异常.可是entity类的注释没有问题,唯一的不正常的地方是这张表比较特殊没有主键,好像在使用hibernate的映射表的时候entity类是必

Mingyang.net:No identifier specified for entity

org.hibernate.AnnotationException: No identifier specified for entity: net.mingyang.modules.system.ConfigGroup org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:277) org.hibernate.cfg.InheritanceState.getElementsToPr

Error:Cannot compile Groovy files: no Groovy library is defined for module 'xxxx' 错误处理

出现 Error:Cannot compile Groovy files: no Groovy library is defined for module 'xxxx' 只要在 project structure 中的modules中左上角的 + 号,然后找到groovy添加即可! 具体可参考: http://stackoverflow.com/questions/43450683/errorcannot-compile-groovy-files-no-groovy-library-is-def

No identifier specified for entity

主键问题   使用hibernate的e-r映射pojo类的时候遇到org.hibernate.AnnotationException: No identifier specified for entity异常.可是entity类的注释没有问题,唯一的不正常的地方是这张表比较特殊没有主键,好像在使用hibernate的映射表的时候entity类是必须要主键的,否则就会报出这个异常. 解决办法自然是add一个主键进去,添加主键的神器就在我的上一篇文章中,这里主要是对实体类的注释,应该做添加 @Id

mysql [1044/1045] Access denied for user 'root'@'localhost' to database 'xxxx' 错误

数据库迁移的时候报了这么个错 但是就很疑惑 我权限都给了啊 用户名密码也对啊 网上找了一堆方案没一个管用 后面再数据库使用root 重新赋权远程账户测试时多留意了一眼 发现了端倪 我在赋权的时候赋给了  'root'@'%' ,而这里报错的是  'root'@'localhost' 然后在重新使用 root 权限赋权 'root'@'localhost' 就一切OK了 GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' IDENTIFIED BY

网页提示[Not allowed to load local resource: file://XXXX]错误

网页通过http 访问时, 点击打开文件的link.在Chrome 中会报 Not allowed to load local resource: file// XXXX 的错误 <!--Add by oscar999--> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document <

windows ipython 出现ImportError: No module named XXXX错误

IPython是一个更好的交互环境,是程序员做数据挖掘的好帮手,但是在Windows下运行IPython可能会出现 <code>ImportError: No module named pickleshare ImportError: No module named simplegeneric ImportError: No module named xxx</code> 提示没有模块XXX 解决方法就是 pip install XXXX Just pip install it.^