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

来源:互联网 发布:java因式分解 编辑:程序博客网 时间:2024/05/17 22:42
 今天hibernate已经开课了,刚写了一个小练习,就出现了一个异常,现在分享如下:

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

异常原因:

<id>元素配置不正确,

<id>元素缺少其子元素<generator></generator>的配置。

解决方法:<id>元素映射了相应数据库表的主键字段,对其子元素<generator class="">,其中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将字段管理交给数据库自己定义。

http://www.cnblogs.com/rong2009/archive/2009/08/14/1546305.html

上面的内容和标题都是来自网上, 其实这个也是我在学习hibernate中第一次遇到的异常。