org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before

来源:互联网 发布:java io书籍 编辑:程序博客网 时间:2024/05/07 01:59

错误描述在用java注解方式中编写的项目程序,在调试时出现如下错误org.hibernate.id.IdentifierGenerationException:ids for this class must be manually assigned before calling save():

解决方法:错误提示是说,id的生成错误,在保存之前,需先生成。找到model层,

@Id@Column(name = "Id", unique = true, nullable = false)@GeneratedValue(strategy = GenerationType.AUTO)public Integer getId() {return this.id;}

加上如上图的“@GeneratedValue(strategy = GenerationType.AUTO)”部分,作为主键的生成策略。即可解决~

           这两天都没怎么搞复习,得抓紧了,学弟还有好几个程序还没看,不管了,先睡觉了~