• 首页
  • 栏目
  • CRM
  • No identifier specified for entity: com.aoshen.entity.User

No identifier specified for entity: com.aoshen.entity.User

  • 2021-11-29
  • Admin

问题描述

在整合JPA的时候,用代码来生成数据库表和数据,在实体类User的主键ID上加@Id注解
有一个坑
在这里插入图片描述
@Id:有两个注解方法,当你引入第二个时候就会报错:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.aoshen.entity.User
	
  • 1
  • 2
  • javax.persistence.Id 是由 JPA 定义的 annotation,记住 JPA 仅适用于关系数据的管理
  • org.springframework.data.annotation.Id 是 Spring 定义的 annotation,用来支持“没有像 JPA 那样的持久化 API”的非关系型数据库或是框架的持久化,因此它常被用于其它 spring-data 项目,例如 spring-data-mongodb 和 spring-data-solr 等

问题解决

使用javax.persistence.Id的@Id注解,问题解决
在这里插入图片描述

原文:https://blog.csdn.net/qq_44890539/article/details/121603317

联系站长

QQ:769220720