我正在使用JPA(hibernate)与Postgres数据库,我的hibernate数据库配置如下:
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;
在进行模式验证时,我遇到了以下错误:
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来解决它?
bigint
,因为你的JPA实体使用了Long
。尝试在JPA实体中使用Integer
或在表定义中使用bigint
。 - user330315