org.hibernate.HibernateException: The database returned no natively generated identity value
problem
使用hibernate新增数据报错
org.hibernate.HibernateException: The database returned no natively generated identity value
reason
table的字段id不是自增特性
solution
设置id为自增特性
-- 将id字段设置为主键,不为空,自增即可
alter table User modify id int(11) not Null auto_increment primary key;
在使用Hibernate进行数据库操作时遇到异常:thedatabasereturnednonativelygeneratedidentityvalue。原因是表的id字段没有设置为主键自增。解决方法是将id字段设置为主键且不允许为空,同时开启自增特性,例如通过SQL语句`alter table User modify id int(11) notNull auto_increment primary key;`完成设置。
1167

被折叠的 条评论
为什么被折叠?



