No identifier specified for entity 从字面上不难看出来是没有设置主键

因为没有为标注为@Entity的实体类注明主键

import lombok.Data;
import org.springframework.data.annotation.Id; import javax.persistence.*; @Data
@Table(name = "user")
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
private String username;
@Column
private String name;
@Column
private Integer age;
}

但实际上bean用@Id和@GenerateValue标注在ID上,仔细观察发现是导错包:import org.springframework.data.annotation.Id;这是Spring提供的;而应该导入javax.persistence.Id,很细微的差别,可能不注意看就错了而且很难去排查问题

区别在于:org.springframework.data.annotation.Id是spring用来支持MongoDB等非关系型数据库的持久化(spring-data-mongodb等);javax.persistence.Id适用于关系型的数据

SpringBoot 遇到 No identifier specified for entity的更多相关文章

  1. springboot No Identifier specified for entity的解决办法

    今天在做一个项目的时候遇到一个问题,实体类忘了指定主键id,然后报如下错误,也是自己粗心大意造成的,在此记录下. java.lang.IllegalStateException: Failed to ...

  2. No identifier specified for entity: springboot-jpa报错No identifier specified for entity

    说明:此次学习使用了springboot框架,jpa注解映射实体类 1,No identifier specified for entity: com.tf.model.User 看到此错误第一反应百 ...

  3. Mingyang.net:No identifier specified for entity

    org.hibernate.AnnotationException: No identifier specified for entity: net.mingyang.modules.system.C ...

  4. No identifier specified for entity

    主键问题   使用hibernate的e-r映射pojo类的时候遇到org.hibernate.AnnotationException: No identifier specified for ent ...

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

    No Identifier specified for entity的错误 此类注解都在 import javax.persistence.*;包下     @Id     @GeneratedVal ...

  6. JPA error org.hibernate.AnnotationException: No identifier specified for entity

    错误:org.hibernate.AnnotationException: No identifier specified for entity 原因:JPA所使用的Entity需要标注@Id,在引用 ...

  7. 报错Caused by: org.hibernate.AnnotationException: No identifier specified for entity:

    Caused by: org.hibernate.AnnotationException: No identifier specified for entity:. 原因: 1.没有给实体类ID 解决 ...

  8. 报错HTTP Status 500 - The given object has a null identifier: cn.itcast.entity.Customer; nested exception is org.hibernate.TransientObjectException: The given object has a null identifier:

    在使用模型驱动封装的时候,要保证表单中name属性名和类中属性名一致,否则将会报错如下: HTTP Status 500 - The given object has a null identifie ...

  9. Springboot- Caused by: org.hibernate.AnnotationException: No identifier specified for entity:

    错误与异常: Caused by: org.hibernate.AnnotationException: No identifier specified for entity: 原因:引用了不对的包, ...

随机推荐

  1. Appium+python自动化(三十八) - Appium自动化测试框架综合实践 - 框架简介-助你冲击高薪,迎娶白富美(超详解)

    简介 好久没有更新博客了,博友们是不是有点等不及了.不好意思啊,中秋节过后太忙了,这篇是好不容易抽点零碎时间写的.从这一篇开始小伙伴或者童鞋们,就跟随宏哥的脚步,一步步的从无到有,从0到1的搭建一个完 ...

  2. .net core 使用Rotativa创建PDF文档

    一.下载Rotaiva 工具  = >  NuGet包管理器  = >  管理解决方案的NuGet程序包 在打开的页面中搜索 Rotativa.AspNetCore 如下图: 选中红框的记 ...

  3. .Net Core 商城微服务项目系列(八):购物车

    最近加班有点多,一周五天,四天加班到11点+,心很累.原因是我当前在的这个组比较特殊,相当于业务的架构组,要为其它的开发组提供服务和监控.所以最近更新的也少,不过这个元旦三天假应该会更新三篇. 这篇是 ...

  4. iOS 组件化路由框架 WisdomRouterKit 的应用

    [前言] 大家好,写作是为了和读者沟通交流,欢迎各位开发者一起了解 WisdomRouterKit SDK 的功能. 关于 iOS 组件化路由方案框架: WisdomRouterKit 的功能介绍,之 ...

  5. Kafka 学习笔记之 Kafka0.11之producer/consumer(Scala)

    Kafka0.11之producer/consumer(Scala): KafkaConsumer: import java.util.Properties import org.apache.kaf ...

  6. Kafka 学习笔记之 Topic日志清理

    Topic日志清理 server.properties: log.cleanup.policy=delete (默认) 1. 按时间维度进行Kafka日志清理 log.retention.hours= ...

  7. Linux修改屏幕分辨率至2K

    使用命令:cvt,与 xrandr 使用cvt命令查看分辨率配置: Modeline后边分别是 modeName 以及 详细的配置 linklee@linklee-270E5G-270E5U:~$ c ...

  8. k8s运维记 - 如何让部署到k8s的kong网关托管自定义静态资源?

    目的 使用kong作为目录/data/reports的静态资源服务器,为了测试,已于目录/data/reports下创建文件report.html,如下: <html> <head& ...

  9. 05-04 scikit-learn库之主成分分析

    目录 scikit-learn库之主成分分析 一.PCA 1.1 使用场景 1.2 代码 1.3 参数 1.4 属性 1.5 方法 二.KernelPCA 三.IncrementalPCA 四.Spa ...

  10. java23种设计模式(二)抽象工厂模式

    我们接着上一章的工厂方法模式继续学习一下抽象工厂模式. 抽象工厂模式:在工厂模式中,如果有多个产品,则就是抽象工厂模式. 例子: 有一个工厂开了两个子公司,专门用来生产电脑配件键盘和鼠标,一个是联想工 ...