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这些注解





猜你喜欢

转载自blog.csdn.net/CaptainJava/article/details/81033245