Semantic exception on emptyString and GetDate

HI,

We were using Spring boot 2.7.1 earlier but are in process of upgrading to spring boot 3 (java17).

1.Validation failed for query for method public abstract java.util.List com.mdesk.studio.ApplicationRepository.findActiveApplication(int)",“name”:“org.springframework.data.repository.query.QueryCreationException
message”:“org.hibernate.query.SemanticException: Cannot compare left expression of type ‘java.sql.Timestamp’ with right expression of type ‘java.lang.String’”,“name”:“java.lang.IllegalArgumentException”,

The Query is as follows

*Query(" SELECT  apps from Scores score where score .enable=:enabled and ( score .endDate is NULL or score.endDate='')")*

List findScoresByFlag(@Param(“enabled”) int enabled);

In the hibernate 6.X upgrade, how can we handle empty string.

  1. In other query
    The Query is as follows
    Query(" SELECT apps from Scores score where score .enable=:enabled and ( score .endDate>=GETDATE() and score .endDate is NULL or score.endDate=‘’)")
    List findScoresByFlagEndDate(@Param(“enabled”) int enabled);

Here we are getting an error like
Cannot compare left expression of type ‘java.sql.Timestamp’ with right expression of type ‘java.lang.Object’",“message”:“org.hibernate.query.SemanticException: Cannot compare left expression of type ‘java.sql.Timestamp’ with right expression of type ‘java.lang.Object’”,“name”:"java.lang.IllegalArgumentException

The entity field is as follows
import java.util.Date;
Column(name = “EndDate”)

  • private Date endDate;*

Can you help us in resolvoing this? Our business case is that the query should be comparing date field with empty string (‘’) / query should compare whether date field is greater that todays(current) date

What are you trying to do when you compare a timestamp with a string? Such a comparison has no meaning. A value can never be equal to a value of a different type. Just remove that comparison score.endDate=''

Hi @beikov ,

Thanks for reading this question

We have such queries in our project that used to work previously.
Also it seems GetDate also doesn’t work now as it’s comparing with object.
How can we handle that?

It worked before because Hibernate ORM 5 just let you do things that might be wrong, which also hindered many optimizations that we now have in ORM 6+. So if you want to stay up-to-date, you will have to write proper HQL.

GetDate is not a registered function in any Hibernate ORM Dialect, but I guess what you want is current_timestamp. Read the documentation about the query language to understand what is allowed.