Problem with @Temporal (TemporalType.DATE)

Hi, I want to display a field in a Java class

@Column(name = "date_of_birth") @Temporal(TemporalType.DATE) private Date dateOfBirth; 

in the field in my table:

 date_of_birth date, 

but now when I try to run my application, I got an exception:

 Caused by: org.hibernate.HibernateException: Wrong column type in public.users for column date_of_birth. Found: date, expected: timestamp 

This is my configuration file:

 dataSource.driverClassName=org.postgresql.Driver hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect hibernate.hbm2ddl.auto=validate hibernate.show_sql=false 

What could be the problem?

Thanks Dawid

+4
source share
2 answers

I think your column type in the database should be timestamp instead of date . But this may not be what you want, seeing that you keep the date of birth.

+1
source

Quite a bit, but I searched for some @Temporal use and came up with your question for 5 years;).

The problem is obvious :) Tracing the system error stack tells you:

"Caused by: org.hibernate.HibernateException: invalid column type in public.users for date_of_birth column. Found: date, expected: timestamp"

You are trying to put a Date object in your DB that expects TimeStamp to be one -> your TemporalType is of type DATE and DB Expects to be TIMESTAMP

@Column (name = "date_of_birth")

@Temporal (TemporalType.DATE)

private Date dateOfBirth;

-1
source

Source: https://habr.com/ru/post/1338841/


All Articles