SpringBoot使用JPA报错:No identifier specified for entity

完整错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'universityRepository' defined in com.gaagle.gaagle.repository.UniversityRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.gaagle.gaagle.vo.ResultVO

这种情况下一般都是实体类@Id注解弄错了(用成了Spring那个)或者数据库表的主键搞成了自增(据说会,没求证)或者实体类没有主键。但是经过反复排查都不是这些原因,而且报错的是一个非实体类ResultVO,我百思不得其解,为什么一个和JPA无关的类会引起JPA报错(其实这就是错误的原因)直到我发现:

 因为JPA必须要给实体指定主键,删掉@Entity注解即可,其实这也属于没有主键那类错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值