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

Custom ResultTransformer for JPA criteria queries

Description

The following JPA criteria query assigns aliases in the projection list:

1 2 3 4 5 6 7 8 CriteriaQuery criteria = cb.createQuery(); Root<Item> i = criteria.from(Item.class); i.alias("i"); criteria.multiselect( i.get("id").alias("itemId"), i.get("name").alias("name"), i.get("auctionEnd").alias("auctionEnd") );

These aliases are not available/preserved in the generated query string:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 Query query = em.createQuery(criteria); org.hibernate.Query hibernateQuery = ((HibernateQuery)query).getHibernateQuery(); assertEquals( hibernateQuery.getQueryString(), "select i.id as itemId, i.name as name, i.auctionEnd as auctionEnd from Item as i" ); // Actual: select i.id, i.name, i.auctionEnd from Item as i assertEquals( hibernateQuery.getReturnAliases(), new String[] {"itemId", "name", "auctionEnd"} ); // Actual: 0, 1, 2

The aliases are also not available in any of the alias-based ResultTransformers. You currently can't apply AliasToBeanResultTransformer to a JPA criteria query.

I've had a look at CriteriaQueryTransformer and it might not be easy to support custom transformers for JPA criteria queries. If this isn't supported, it should probably be documented.

Environment

None

Status

Assignee

Unassigned

Reporter

Christian Bauer

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

4.3.0.Beta1

Priority

Minor