Uploaded image for project: 'Hibernate ORM'
  1. Hibernate ORM
  2. HHH-6747

ClassCastException when rendering SimpleCaseExpression

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      Description

      When creating a SimpleCase using CriteriaBuilder.selectCase(Expression<?> arg0), a classcast exception will be thrown when the query is rendered to a TypedQuery.

      CriteriaQuery<Customer> query = builder.createQuery(Customer.class);
      Root<Customer> root = query.from(Customer.class);
      query.select(root);
      
      SimpleCase<String, Integer> orderCase = builder.selectCase(root.get(Customer_.EMail));
      orderCase = orderCase.when("test@test.com", 1);
      orderCase = orderCase.when("test2@test.com", 2);
              
      query.orderBy(builder.asc(orderCase.otherwise(0)));
              
      em.createQuery(query);
      
      Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to org.hibernate.ejb.criteria.Renderable
      	at org.hibernate.ejb.criteria.expression.SimpleCaseExpression.render(SimpleCaseExpression.java:146)
      	at org.hibernate.ejb.criteria.CriteriaQueryImpl.render(CriteriaQueryImpl.java:346)
      	at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:223)
      	at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441)
      

      See attachement for a reproduction project.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                3 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - Not Specified
                  Not Specified
                  Logged:
                  Time Spent - 35m
                  35m