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 。


目录
相关文章
MGA (Managed Global Area) Reference Note (Doc ID 2638904.1)
MGA (Managed Global Area) Reference Note (Doc ID 2638904.1)
223 0
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