jakartaee / persistence

https://jakartaee.github.io/persistence/
Other
191 stars 55 forks source link

"org.hibernate.query.sqm.tree.expression.SqmCaseSimple does not define or inherit an implementation..." when using SimpleCase but not when using Case? #392

Closed yaharga closed 12 months ago

yaharga commented 1 year ago

I'm getting the error in the title when I am trying to do the following:

CriteriaBuilder.SimpleCase<Integer, String> simpleCase = stringList.stream().reduce(
  criteriaBuilder.selectCase(criteriaBuilder.function("LEAST", Integer.class, expressionMap.values.toArray(Expression[]::new))),
  (caseBuilder, expressionKey) -> caseBuilder.when(
    expressionMap.get(expressionKey),
    expressionKey
  ),
  (previousCaseBuilder, nextCaseBuilder) -> previousCaseBuilder
);

However, if I use a Case instead of SimpleCase, it works fine:

CriteriaBuilder.Case<String> case = stringList.stream().reduce(
  criteriaBuilder.selectCase(),
  (caseBuilder, expressionKey) -> caseBuilder.when(
    criteriaBuilder.equal(
      criteriaBuilder.function("LEAST", Integer.class, expressionMap.values.toArray(Expression[]::new)),
      expressionMap.get(expressionKey)
    ),
    expressionKey
  ),
  (previousCaseBuilder, nextCaseBuilder) -> previousCaseBuilder
);

The error I get is the following:

Receiver class org.hibernate.query.sqm.tree.expression.SqmCaseSimple does not define or inherit an implementation of the resolved method 'abstract jakarta.persistance.criteria.criteriaBuilder$SimpleCase when(jakarta.persistance.criteria.Expression, jakarta.persistance.criteria.Expression)' of interface jakarta.persistance.criteria.criteriaBuilder$SimpleCase.

When I check the method, everything looks fine. Even the IDE doesn't complain (see code).

beikov commented 1 year ago

This could potentially be a bug in the Hibernate code, but to be sure, we need a reproducer for this. Please use the test case template (https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) to reproduce this, and if you are successful, attach that to a new issue in the issue tracker(https://hibernate.atlassian.net).

gavinking commented 12 months ago

This does not appear to be an issue with the JPA spec.