6

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.

3
  • Very similar to wrong column type in “table” for column Found: int8, expected: int4 Commented Oct 4, 2016 at 15:22
  • 1
    I know nothing about JPA, but the error message suggests that it expects the column to be defined as bigint because your JPA entity uses Long. Try to either use Integer in the JPA entity or bigint in the table definition. Commented Oct 4, 2016 at 17:05
  • 1
    @suraj bahi Where you able to solve it? I am facing the same problem now. Commented Jun 20, 2018 at 18:21

1 Answer 1

11

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Is not it ? Postgres: smallint to Java --> short

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.