identity和assigned 的区别

简介: 在使用struts+hibernate开发过程中,数据的持久化操作时出现了“org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ”的错误,首先检查了数据库,发现建表时没有把ID设置成自动递增,修改之后还是有错误,

在使用struts+hibernate开发过程中,数据的持久化操作时出现了“org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ”的错误,首先检查了数据库,发现建表时没有把ID设置成自动递增,修改之后还是有错误,这时想到hibernate的功能是对象关系映射,数据库的内容已经生成映射关系,于是又去查看了XXX.hbm.xml文件,发现id字段是这样的:


<generator class="assigned" />这句出现了问题,assigned应该改成identity。那这两个的主要区别是什么呢?

在用Hibernate的时候,当有表中的主键是库自动生成的时候将使用identity。而当是自己添加的时候则需要改为assigned。因为assigned是指指定的,分配的, 如果你不赋予他值,那么他是不能实现的. 需要人工,自己把某个东西赋予给它 所以是assigned 。


目录
相关文章
component set load logic - why coms_pcat_bob is accessed during product search
component set load logic - why coms_pcat_bob is accessed during product search
111 0
component set load logic - why coms_pcat_bob is accessed during product search
|
Python
如何查看某个ABAP user针对某个authorization object的assignment status
如何查看某个ABAP user针对某个authorization object的assignment status
133 0
test case id - hash generation logic
Created by Wang, Jerry, last modified on Jul 06, 2016
105 0
test case id - hash generation logic
|
SQL 数据库 数据库管理
Replication-Replication Distribution Subsystem: agent xxxxxx failed. Column names in each table must be unique
原文:Replication-Replication Distribution Subsystem: agent xxxxxx failed. Column names in each table must be unique   最近遇到一个关于发布订阅(Replication)的奇葩问题,特此记录一下这个案例。
1019 0
Quaternion.identity是什么意思?
Quaternion.identity就是指Quaternion(0,0,0,0),