ids for thisclass must be manually assigned before callingsave()
来源:互联网 发布:蓝桥杯单片机 编辑:程序博客网 时间:2024/06/05 16:15
ids for thisclass must be manually assigned before callingsave()
引起问题的原因:
由Hibernate根据数据库表自动生成的"类名.hbm.xml"映射文件引起的。
首先我的表(Info)由两个字段组成,即:
int id;//主建
String name;
(自己做测试,所以就简单的建了个表)
由Hibernate生成的Info.hbm.xml中是这样写的:
-----------------------------------------------------
-----------------------------------------------------
这个是必须有的。它是用来定义实体的标识属性(对应数据库表的主键)
而我这里由于id本身就是主键,所以column的属性便是id
下面是很关键的一点,由于一时兴趣,于是找了很多资料,关于它的解释是:用于指定主键的生成策略。它的值有多,下面是转来的:
--------------------------------------------------------------------------------
“assigned”
主键由外部程序负责生成,在
“hilo”
通过hi/lo
“seqhilo”
与hilo
“increment”
主键按数值顺序递增。此方式的实现机制为在当前应用实例中维持一个变量,以保存着当前的最大值,之后每次需要生成主键的时候将此值加1作为主键。这种方式可能产生的问题是:不能在集群下使用。
“identity”
采用数据库提供的主键生成机制。如DB2、SQL
“sequence”
采用数据库提供的
“native”
由
“uuid.hex”
由
“uuid.string”
与uuid.hex
“foreign”
使用另外一个相关联的对象的标识符作为主键。
--------------------------------------------------------------------------------
看了上面的介绍,再看看代码,原来是属性设置有问题。
然后改为"identity"、"native"问题便解决。
- ids for thisclass must be manually assigned before callingsave()
- BUG:ids for this class must be manually assigned before....
- ids for this class must be manually assigned before calling save():***错误说明
- error:ids for this class must be manually assigned before calling save():
- error:ids for this class must be manually assigned before calling save()
- ids for this class must be manually assigned before calling save()
- error:ids for this class must be manually assigned before calling save():
- ids for this class must be manually assigned before calling save() hibernate
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():
- IdentifierGenerationException: ids for this class must be manually assigned before calling save()
- hibernate保存数据的时候出现:ids for this class must be manually assigned before 错误
- ids for this class must be manually assigned before calling save()..
- HibernateSystemException--ids for this class must be manually assigned before calling save()
- error:ids for this class must be manually assigned before calling save():
- 关于 error:ids for this class must be manually assigned before calling save(): 的解决方案
- ids for this class must be manually assigned before calling save():
- 工作札记--“ids for this class must be manually assigned before calling save”解决办法
- Hibernate的Criteria方法
- struts的token 防止form表单…
- struts2+displaytag翻页时In…
- jquery 对select中的option…
- Hibernate一对多(单向)
- ids for thisclass must be manually assigned before callingsave()
- spring - context:component-scan
- Struts2输入校验总结
- [自学问题总结]const 和 static readonly 区别
- DFS-hdu-2821-Pusher
- 商业智能给数据获取带来的局部效益案例
- Android编程习惯
- Java IO学习笔记:概念与原理
- java.io.IOException: Attempted read from closed stream.