我正在使用postgres / postgis进行休眠。 当我将Hibernate属性“hibernate.hbm2ddl.auto”从“update”切换为validate时,我得到了这个异常:
引起:org.hibernate.HibernateException:列type_id的历史记录中的列类型错误。找到:int8,预期:int4
首先我认为hibernate需要对另一个表的每个引用都是int8。我选择将列type_id更改为bigint但没有成功。我没有想法。有人可以帮忙吗?
我的实体以这种方式构建:
@Entity
public class History{
@Id
protected Integer id;
private Date created_on;
private Date timestamp;
@ManyToOne
private DataType type;
private Double value;
}
@Entity
public class DataType{
@Id
private Integer id;
private String cname;
private Date created_on;
private String cunit;
}
这些是db中的表定义:
历史
Column | Type | Modifiers
------------+-----------------------------+-----------------
id | integer | not null default nextval('history_id_seq'::regclass)
created_on | timestamp without time zone |
timestamp | timestamp without time zone |
value | double precision |
type_id | bigint | not null
Indexes:
"pk_history" PRIMARY KEY, btree (id)
Foreign-key constraints:
"fk_history" FOREIGN KEY (type_id) REFERENCES type(id)
类型
Column | Type | Modifiers
-------------+-----------------------------+-----------
id | bigint | not null
cname | character varying(255) |
created_on | timestamp without time zone |
cunit | character varying(255) |
Indexes:
"type_pkey" PRIMARY KEY, btree (id)
Referenced by:
TABLE "history" CONSTRAINT "fk_history" FOREIGN KEY (type_id) REFERENCES type(id)