【发布时间】:2015-11-27 13:22:03
【问题描述】:
我有一个主键为 SERIAL 类型的表。 此主键受以下序列影响:
CREATE SEQUENCE swq
INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807
START 1 CACHE 1;
我的问题是:为什么主键在第一次执行 saveorUpdate() 方法后会创建第一条记录,但将 id 字段插入为零 (0) 而不是 ONE(1)?
来自 OP 的评论:
@Entity @Table(name = "table", schema = "schem")
public class tableBE implements java.io.Serializable
{
private int idmotiv;
@Id @Column(name = "_id", unique = true, nullable = false)
public int getIdmot() { return this.idmot; }
}
【问题讨论】:
-
请添加映射类定义和示例代码
-
@Entity @Table(name = "table", schema = "schem") public class tableBE implements java.io.Serializable { private int idmotiv;@Id @Column(name = "_id", unique = true, nullable = false) public int getIdmot() { return this.idmot; } -
这些类是在 Eclipse 中通过 Hibernate 插件生成的。但我认为问题出在 PGdatabase 方面。我只是创建这个实体并调用方法
getcurrentsession.saveorupdate(entidad) -
关注@Viswanath D 解决方案
标签: database hibernate postgresql sequence