org.hibernate.id.IdentifierGenerationException

来源:百度文库 编辑:神马文学网 时间:2024/04/28 13:24:05

org.hibernate.id.IdentifierGenerationException:我的第一个hibernate异常

   今天hibernate已经开课了,刚写了一个小练习,就出现了一个异常,现在分享如下:

异常信息:org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():

异常原因:

元素配置不正确,

元素缺少其子元素的配置。

解决方法:元素映射了相应数据库表的主键字段,对其子元素,其中class的取值可以为increment、identity、sequence、hilo、native......等,更多的可参考hibernate参考文档,一般取其值为native 。

MySQL:identity,increment,hilo,native.
SQL Server:identity,increment,hilo,native.
Oracle:sequence,seqhilo,increment,native.
跨平台开发:native.

native将字段管理交给数据库自己定义。