org.hibernate.id.IdentifierGenerationException
来源:互联网 发布:虚拟机mac共享文件夹 编辑:程序博客网 时间:2024/05/16 17:07
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():
引起问题的原因:
就是那个由Hibernate根据数据库表自动生成的"类名.hbm.xml"映射文件引起的。
由Hibernate生成的Info.hbm.xml中是这样写的:
-----------------------------------------------------
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned"/>
</id>
-----------------------------------------------------
<id>这个是必须有的。它是用来定义实体的标识属性(对应数据库表的主键)
这里由于id本身就是主键,所以column的属性便是id
是<Generator>属性设置有问题。
解决办法:
然后改为"identity"、"native"问题便解决。
------------------------------------------------------------------------------
下面是很关键的一点<generator>,由于一时兴趣,于是找了很多资料,关于它的解释是:用于指定主键的生成策略。它的值有多,下面是转来的:
--------------------------------------------------------------------------------
“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”
使用另外一个相关联的对象的标识符作为主键。
- org.hibernate.id.IdentifierGenerationException:
- org.hibernate.id.IdentifierGenerationException
- org.hibernate.id.IdentifierGenerationException
- org.hibernate.id.IdentifierGenerationException
- org.hibernate.id.IdentifierGenerationException异常
- org.hibernate.id.IdentifierGenerationException错误提示
- org.hibernate.id.IdentifierGenerationException错误解析
- org.hibernate.id.IdentifierGenerationException错误解决方法
- org.hibernate.id.IdentifierGenerationException:我的第一个hibernate异常
- Exception in thread "main" org.hibernate.id.IdentifierGenerationException:
- org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property
- Hibernate报错:org.hibernate.id.IdentifierGenerationException:ids for this class must be manually assig
- 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():
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before
- org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before
- Boost下载安装编译配置使用指南(含Windows和Linux)
- Android wifi设计原理(源码分析)
- php 读取rss
- AJAX的原生态写法
- C#中ref 与out
- org.hibernate.id.IdentifierGenerationException
- 比较两个数据库的结构(只比较表名是否相同)
- Xml 串行化类型
- 有关VM下DOS的共享文件夹问题
- Linux Shell变量的使用
- Boost下载安装编译配置使用指南(含Windows和Linux)
- 异步io libaio.so
- 又找到一篇改良版……
- Ubuntu下FTP工具推荐