I am using JPA (hibernate) with Postgres database, my hibernate database configuration are as below:
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
properties.setProperty("hibernate.hbm2ddl.auto","validate");
I have a table with property created_by_user_id
CREATE TABLE dppm_main.user_account_profile
( ....//other columns
created_by_user_id integer
)
Mapped to JPA entity as below:
@Column(name = "created_by_user_id")
private Long createdByUserId;
While doing schema validation, I am getting following error:
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)]**
How can I fix it? I am having this issue in many places so is it possible to fix it by extending PostgreSQL82Dialect instead of columnDefinition.
The exception is clearly speaking about types mismatch between Java types and Postgres types.
I didn't understand clearly what is your type in Postgres, so I'll point a few types conversions:
Postgres: smallint to Java --> java.lang.Short
Postgres: integer to Java --> java.lang.Integer
Postgres: bigint to Java --> java.lang.Long
With that being said, just change from:
@Column(name = "created_by_user_id")
private Long createdByUserId;
To:
@Column(name = "created_by_user_id")
private Integer createdByUserId;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With