We're updating the issue view to help you get more done. 

ClassCastException when rendering SimpleCaseExpression

Description

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

1 2 3 4 5 6 7 8 9 10 11 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);
1 2 3 4 5 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.

Environment

SQL Server 2005

Status

Assignee

Steve Ebersole

Reporter

Anne Buit

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

3.6.7

Priority

Minor