Exception resolution: org.hibernate.AnnotationException:No identifier specified for entity

Exception:项目启动时报错,org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.***.view.entity.vo.ClusterTermVo

意思是没有为实体类制定id标识。

当我们使用hibernate或者sbring data jpa框架时,有时候我们的实体类并不需要id,但你在实体类上加了@Entity注解,hibernate在创建bean的时候就会包以上错误。

我们可以在实体类中添加

@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
private String id;

即可。


如果你不需要讲此类用作jpa/hibernate的取值映射使用,而只是用于普通类使用或者用于jdbcTemplate,完全可以去掉@Entity。也不需要加@Id这些注解





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值