2016-10-04 59 views
0

我使用JPA(休眠)与Postgres数据库,我的休眠数据库配置情况如下:PostgreSQL的JPA架构验证9.5

properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); 
properties.setProperty("hibernate.hbm2ddl.auto","validate"); 

我有一个表属性created_by_user_id

CREATE TABLE dppm_main.user_account_profile 
(....//other columns 
    created_by_user_id integer 
) 

映射到JPA实体如下:

@Column(name = "created_by_user_id") 
private Long createdByUserId; 

在做模式验证时,我g以下错误:

org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column 
type encountered in column [created_by_user_id] in table [user_account_profile]; 
**found [int4 (Types#INTEGER)], but expecting [int8 (Types#BIGINT)]** 

我该如何解决?我在很多地方都有这个问题,所以可以通过扩展PostgreSQL82Dialect而不是columnDefinition来修复它。

+0

非常相似[错列式“表“列找到:int8,expected:int4](http://stackoverflow.com/questions/27230426/wrong-column-type-in​​-table-for-column-xy-found-int8-expected-int4) –

+1

我知道没有关于JPA的消息,但是错误消息表明它期望列被定义为'bigint',因为你的JPA实体使用'Long'。试着在JPA实体中使用'Integer'或者在表格定义中使用'bigint'。 –

回答

1

这个例外很明显是Java类型和Postgres类型之间的类型不匹配。

我没了解清楚什么是你在Postgres类型,所以我会点几个类型的转换:

Postgres的smallint到Java - >java.lang.Integer

的Postgresinteger到Java - >java.lang.Integer

个Postgres的bigint到Java - >java.lang.Long

有了这样说,只是改变来自:

@Column(name = "created_by_user_id") 
private Long createdByUserId; 

要:

@Column(name = "created_by_user_id") 
private Integer createdByUserId;