springboot 2.2.5 在使用jpa时,出现异常BeanCreationException时的解决办法

springboot 2.2.5 在使用jpa时,出现异常BeanCreationException时的解决办法

实体类为:

//使用JPA注解配置映射关系
@Entity //告诉JPA这是一个实体类(和数据表映射的类)
@Table(name = "user") //指定和哪一个数据表进行映射;如果省略默认表明就是类名小写
public class User {

    @Id //这是一个主键
    @GeneratedValue(strategy = GenerationType.AUTO) //自增组件
    private Integer id;

导入的@Id包为:

import org.springframework.data.annotation.Id;

出现的异常为:

ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 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.atguigu.springboot.entity.User

致错原因:导入@Id包错误,应该导入的是:

import javax.persistence.Id;

完美解决:

2020-03-08 19:57:32.965  INFO 9356 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-08 19:57:33.755  INFO 9356 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-08 19:57:33.758  INFO 9356 --- [           main] c.a.s.SpringBoot06DataJpaApplication     : Started SpringBoot06DataJpaApplication in 28.325 seconds (JVM running for 31.204)

可以作为参考。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值