20180801问题记录总结

1.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.imooc.dataobject.OrderMaster

重点是红色粗体部分,这是因为使用@Entity这个注解的类没有设置哪个字段是主键

网上找的解释:

原因:以上文字没写或者写错了地方,导致找不到主键。
解决办法:在数据库表对应实体(entity.java)的方法:getId()前加上该段文字。

2.已经第二次遇到这个问题了

@UpdateTimestamp
@Column(insertable=false)
private Date createTime;


@UpdateTimestamp
@Column(insertable=false)
private  Date updateTime;

这两个字段,如果在代码里面不赋值,给mysql数据库传入空,数据库会报错,因为这两个字段的值不可以为null

这个时候,给这两个字段在数据库映射类中加上,这样hibernate就不会主动插入这个字段,提交给数据库了,也就不会报错了

猜你喜欢

转载自blog.csdn.net/weixin_30563001/article/details/81327279