Hibernate出现Caused by: java.sql.SQLException: Field 'id' doesn't have a default value原因

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Interesting_Talent/article/details/82494623

原因:设计mysql的时候主键id没有设置为自增造成的

本来不设置也没事,但是如果字段用了主键策略就不行了,例如用了注解的

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

所以,更改表结构就可以了

修改方案:更改表结构语句方法

alter table portal_product_ingredient modify column id int auto_increment;

猜你喜欢

转载自blog.csdn.net/Interesting_Talent/article/details/82494623