ids for this class must be manually assigned before calling save(): com
2017-10-14 11:16
519 查看
这种报错 是用Hibernate时自动生成的pojo 数据库表自动生成的"类名.hbm.xml"映射文件引起的
主键生成方式不一样
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.pojo.HClazz" table="H_CLAZZ" schema="JIANGYANG">
<id name="cid" type="java.lang.Long">
<column name="CID" precision="10" scale="0" />
<generator class="assigned" />自动生成的是这个
<generator class="increment" />//改成increment就好啦
</id>
<property name="cname" type="java.lang.String">
<column name="CNAME" length="40" />
</property>
以下几种主键生成
“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 数据库中。
主键生成方式不一样
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.pojo.HClazz" table="H_CLAZZ" schema="JIANGYANG">
<id name="cid" type="java.lang.Long">
<column name="CID" precision="10" scale="0" />
<generator class="assigned" />自动生成的是这个
<generator class="increment" />//改成increment就好啦
</id>
<property name="cname" type="java.lang.String">
<column name="CNAME" length="40" />
</property>
以下几种主键生成
“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 数据库中。
相关文章推荐
- hibernate 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()
- ids for this class must be manually assigned before calling save():Xxx
- 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”解决办法
- 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():
- IdentifierGenerationException: 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().. .
- error:ids for this class must be manually assigned before calling save():
- ids for this class must be manually assigned before calling save():
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()
- ids for this class must be manually assigned before calling save()..