-
Notifications
You must be signed in to change notification settings - Fork 862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Casebuilder could not determine data type for searched case statement #1968
Comments
Somehow, the syntax you mentioned is not fitting, could you try this: new CaseBuilder()
.when(foo.id.eq(Expressions.asNumber(1))).then(false)
.when(foo.id.eq(Expressions.asNumber(2))).then(true)
.otherwise(Expressions.nullExpression(Boolean.class)) See the extra |
My apologies - typo with copying over the code. I still get the same result. |
I guess you can give a try for this solution that was related to Hibernate doing something with lietrals: http://stackoverflow.com/questions/26648491/querydsl-could-not-determine-data-type-for-searched-case-statement#answer-27190771 |
Hibernate doesn't know what type Using templates like the answer on stackoverflow is an option. Other than that, it's a hibernate issue. |
Hi, I'll give it a try - although I've tried numerous templates. Is there a specific one? In 3.x I was using NumberTemplate and BooleanTemplate but in 4 I believe it is now different? I've tried: Expressions.asBoolean() As I did mention though, this syntax:
results in a compilation error (ambiguous method call with '.then(Expressions.asBoolean(false))' - both overridden in ComparableExpression and Predicate apply. I can make it work by casting the result to Expression, is this expected behaviour? |
The old code:
new CaseBuilder() .when(foo.id.eq(NumberTemplate.create(Integer.class, "1").then(BooleanTemplate.FALSE) .when(foo.id.eq(NumberTemplate.create(Integer.class, "2").then(BooleanTemplate.TRUE) .otherwise(new NullExpression<>(Boolean.class)
I've tried replacing it with
new CaseBuilder() .when(foo.id.eq(Expressions.asNumber(1).then(false) .when(foo.id.eq(Expressions.asNumber(2)).then(true) .otherwise(Expressions.nullExpression(Boolean.class))
which didn't work. I get the error
org.hibernate.QueryException: Could not determine data type for searched case statement
I then tried using Expressions.constant(), which also didn't work. Finally, I tried Expressions.asBoolean() and Expressions.FALSE, which doesn't compile due to ambiguous method call: valid in Predicate and ComparableExpression.
I should note that explicitly casting Expressions.FALSE to Expression does allow the code to compile (and generate valid SQL), although now there are unchecked warnings.
The text was updated successfully, but these errors were encountered: