I have Entity class where I have
private Timestamp startDate;private Timestamp endDate;
field which is mapped to start_date, end_date -> timestamp with time zone in PostgreSQL table.
After updating from Spring boot 2.7.18, Java 11 to 3.2.7, Java 17
I am getting error:
java.lang.IllegalArgumentException: org.hibernate.query.SemanticException: Cannot compare left expression of type 'java.sql.Timestamp' with right expression of type 'java.lang.Object'
How I can fix it?
Query I have is
@Query("SELECT cn FROM CnEntity cn WHERE cn.isActive = true AND cn.startDate < now() And cn.endDate > now() ORDER by cn.endDate ASC)
6
Take a look at https://docs.jboss.org/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#basic-temporal
The mappings have changed, and you may want to use either OffsetDateTime or ZonedDateTime instead of Timestamp.
The doc says:
Applying @Temporal to java.sql.Date, java.sql.Time, java.sql.Timestamp
or any of the java.time types is considered an exception
4
Try to replace now() by CURRENT_TIMESTAMP
@Query("SELECT cn FROM CnEntity cn WHERE cn.isActive = true AND cn.startDate < CURRENT_TIMESTAMP And cn.endDate > CURRENT_TIMESTAMP ORDER by cn.endDate ASC)