-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Spring Data fails to detect proper enumeration type for case/when/then in sum with CriteriaBuilder #3871
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
Comments
I fail to see any connection to Spring Data. This is a Hibernate issue, especially given that you're using the JPA API only. Please file a ticket with the Hibernate issue tracker. |
Hello @mp911de , sorry for coming back. I did as requested - and the Hibernate guys say, it's a Spring issue. There must be an issue with Spring Boot/Data 3.4.5 / Hibernate-Core 6.6.13.Final / H2 2.3.232. Thanks. |
Sorry, we need a clean reproducer for this, preferable as a Github repository. In the Hibernate issue you talk about switching Spring versions, but the reproducer linked in the same issue doesn't mention Hibernate at all. Some Notes
|
Hello @schauder, the test case you're asking for is present already, please see hibernate/hibernate-test-case-templates#507 . Note: in the pom.xml, I've configured both, Spring Boot 3.4.5 AND 3.2.12, with the first being active right now. Concerning your notes:
Thanks. |
Hello @schauder I just played a bit w/ the test. I changed the dialect to org.hibernate.dialect.H2Dialect and disabled schema creation (boot would fail otherwise).
... H2Dialect therefore generates the correct statement, applying the casts to the when/thens. I know, one shouldn't use H2 with PostgresDialect - but still: why is just the cast not working? Thanks + have a good week. |
Well, the "SQL Standard" is a bit of a joke. Every database out there has its own tweaks and special pieces of syntax or semantics. Some in memory databases try to emulate other databases, but that is always just a best effort approximation. If you want to know why exactly H2 doesn't support the original statement, I recommend a H2 forum, or StackOverflow with H2 tag. |
Hello,
our application uses CriteriaBuilder to select data from the DB. In this case, we're returning conditional results:
The x in the code above represents an enumeration, which is saved using its ordinal numbers.
This works perfectly when using Spring Boot/Spring Data 3.2.12 for tests and productive usage.
But switching to version 3.4.5, it suddenly fails for the tests tests (H2 - 2.2.224 / 2.3.232) - while the productive (Postgres) usage continues to succeed.
The query we're using - look esp. for the
criteriaBuilder.selectCase(..).when(..).otherwise(...).as(..)
partSomehow, the return type of the values produced by the CASE/WHEN/THEN is not detected properly, leading to
org.h2.expression.SimpleCase:optimize(SessionLocal)
returns TypeInfo.TYPE_VARCHAR - which is not correct. But I don't know, if that's aI've attached
query-sum-enumeration-test.zip, containing the sample code - just jump in the pom.xml between the two Spring Boot versions.
Thanks for your help and do not hesitate to contact me, if you have any questions.
Stefan
The text was updated successfully, but these errors were encountered: