Change By: Christian Bauer (20/Apr/13 11:17 PM)
Description: The following JPA criteria query assigns aliases in the projection list:

{code}
CriteriaQuery
<Tuple>  criteria = cb. createTupleQuery 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")
);
{code}

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

{code}

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
{code}

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.
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