Issue Type: Improvement Improvement
Affects Versions: 4.3.0.Beta1
Assignee: Unassigned
Created: 20/Apr/13 11:13 PM
Description:

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

CriteriaQuery<Tuple> criteria = cb.createTupleQuery();
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:


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.

Project: Hibernate ORM
Priority: Minor Minor
Reporter: Christian Bauer
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira