ids for this class must be manually assigned before calling save():
来源:互联网 发布:便携电脑推荐 知乎 编辑:程序博客网 时间:2024/06/05 05:30
引起问题的原因:
由Hibernate根据数据库表自动生成的"类名.hbm.xml"映射文件引起的。
--------------------------------------------------------------------------------
“assigned”
主键由外部程序负责生成,在 save() 之前指定一个。
“hilo”
通过hi/lo 算法实现的主键生成机制,需要额外的数据库表或字段提供高位值来源。
“seqhilo”
与hilo 类似,通过hi/lo 算法实现的主键生成机制,需要数据库中的 Sequence,适用于支持 Sequence 的数据库,如Oracle。
“increment”
主键按数值顺序递增。此方式的实现机制为在当前应用实例中维持一个变量,以保存着当前的最大值,之后每次需要生成主键的时候将此值加1作为主键。这种方式可能产生的问题是:不能在集群下使用。
“identity”
采用数据库提供的主键生成机制。如DB2、SQL Server、MySQL 中的主键生成机制。
“sequence”
采用数据库提供的 sequence 机制生成主键。如 Oralce 中的Sequence。
“native”
由 Hibernate 根据使用的数据库自行判断采用 identity、hilo、sequence 其中一种作为主键生成方式。
“uuid.hex”
由 Hibernate 基于128 位 UUID 算法 生成16 进制数值(编码后以长度32 的字符串表示)作为主键。
“uuid.string”
与uuid.hex 类似,只是生成的主键未进行编码(长度16),不能应用在 PostgreSQL 数据库中。
“foreign”
使用另外一个相关联的对象的标识符作为主键。
--------------------------------------------------------------------------------
看了上面的介绍,再看看代码,应该是<Generator>属性设置有问题。
由Hibernate根据数据库表自动生成的"类名.hbm.xml"映射文件引起的。
<id name="id" type="java.lang.Integer"> <column name="ID" scale="0" /> <generator class="<span style="font-size:14px;">assigned</span>"/> </id>
很关键的一点<generator>,改为native解决问题。
下面是转来的:--------------------------------------------------------------------------------
“assigned”
主键由外部程序负责生成,在 save() 之前指定一个。
“hilo”
通过hi/lo 算法实现的主键生成机制,需要额外的数据库表或字段提供高位值来源。
“seqhilo”
与hilo 类似,通过hi/lo 算法实现的主键生成机制,需要数据库中的 Sequence,适用于支持 Sequence 的数据库,如Oracle。
“increment”
主键按数值顺序递增。此方式的实现机制为在当前应用实例中维持一个变量,以保存着当前的最大值,之后每次需要生成主键的时候将此值加1作为主键。这种方式可能产生的问题是:不能在集群下使用。
“identity”
采用数据库提供的主键生成机制。如DB2、SQL Server、MySQL 中的主键生成机制。
“sequence”
采用数据库提供的 sequence 机制生成主键。如 Oralce 中的Sequence。
“native”
由 Hibernate 根据使用的数据库自行判断采用 identity、hilo、sequence 其中一种作为主键生成方式。
“uuid.hex”
由 Hibernate 基于128 位 UUID 算法 生成16 进制数值(编码后以长度32 的字符串表示)作为主键。
“uuid.string”
与uuid.hex 类似,只是生成的主键未进行编码(长度16),不能应用在 PostgreSQL 数据库中。
“foreign”
使用另外一个相关联的对象的标识符作为主键。
--------------------------------------------------------------------------------
看了上面的介绍,再看看代码,应该是<Generator>属性设置有问题。
0 0
- 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 save():
- IdentifierGenerationException: ids for this class must be manually assigned before calling save()
- 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”解决办法
- ids for this class must be manually assigned before calling save()..
- ids for this class must be manually assigned before calling save()
- message ids for this class must be manually assigned before calling save(): ID 的问题
- ids for this class must be manually assigned before calling save():
- Debian 7 配置安装Java jdk及Eclipse for C/C++
- Android的消息通知--Notification
- 反向运算和增量赋值
- 程序员转型应该考虑的几个方面
- springmvc+spring+mybatis整合心得
- ids for this class must be manually assigned before calling save():
- HEVC中SAO--自适应样点补偿 详细分析解读
- 应用与MPlayer通过slave模式进行信息交换
- OC 的 #pragma mark - 在Swift 里的代替方法
- 给UIButton添加(类别)方法,方便批量创建button
- UIImage图片缩放到指定大小尺寸
- 探究javascript mvc(二)
- HEVC细琐杂项 持续更新~
- 多路归并排序