JPQL issues with Spring boot 3 migration

I’m in process of upgrading from spring boot 2.x to 3.x and encountered a similar issue.

In my entity I have a LocalDateTime field which in my query (JPQL) I compare against ‘9999-12-31 23:59:00’

@Query("UPDATE DetailsEntity wt SET wt.updateBy = :user, wt.endDate = :endDate WHERE wt.type = :type AND wt.bankwideForecast = :scenario AND wt.endDate = '9999-12-31 23:59:00'")
void updateUpdatedByAndEndDate(@Param("user") String user, @Param("endDate") LocalDateTime endDate, @Param("type") RecordType type, @Param("scenario") String scenario);

After migration, I’m getting below error:

Caused by: org.hibernate.query.SemanticException: Cannot compare left expression of type 'java.time.LocalDateTime' with right expression of type 'java.lang.String'

How do I get around this?

@ beikov Can you please help with this?

What if you pass the value 9999-12-31 23:59:00 as a LocalDateTime param of your updateUpdatedByAndEndDate method ?
It should fix your issue and it will be also more generic.

I have the same error but with the “now()” function on my query:

@Query("SELECT count(u) FROM User u JOIN u.userEntities AS ue WHERE = :entityUUID AND u.endValidity >= now() ")
int countValidUsersByEntity(@Param("entityUUID") UUID entityUUID);

For this column:

@Column(name = "end_validity")
private LocalDateTime endValidity;

This error appeared after the spring boot 3 migration

Cannot compare left expression of type 'java.time.LocalDateTime' with right expression of type 'java.lang.Object'

Have you some idea ?

@fykidwai instead of comparing a timestamp attribute to a string you should be using Hibernate’s datetime literals, for example:

wt.endDate = datetime '9999-12-31 23:59:00'

@LudoRb I suppose the now() expression in your query is a custom function of your database vendor. Please use Hibernate standard current_timestamp instead.

1 Like

@mbladel Thanks ! It’s working