feezh

我们之所以努力赚钱,是为了让父母为自己买东西时能像给我们买东西时一样大方!
随笔 - 7, 文章 - 0, 评论 - 10, 引用 - 0
数据加载中……

【转】org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ***(POJO类,及持久化类名)

错误篇1:
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ***(POJO类,及持久化类名)

分析及解决:

你要操作的数据表中的id(即主键)的类型设置成了“自动增长类型”,而在你的

hibernate.cfg.xml中,id的生成方式是assigned,即
<id name="id" type="integer">
            <column name="id" />
            <generator class="assigned" />
</id>
这种搭配是矛盾的!

主键的assigned生成方式由程序自动生成表的主键,即在你的测试程序中要调用setId()方法,且必

须在调用save()前调用(或者说在调用save()前必须指定id,其实就是说,主键值不能为空!)。
把主键的生成方式改为native,它的特征是能够根据底层数据库自动选择主键生成方式。
转自:http://www.iteye.com/topic/201035

posted on 2012-05-28 10:14 feezh 阅读(3446) 评论(0)  编辑  收藏 所属分类: 错误集


只有注册用户登录后才能发表评论。


网站导航: