Hibernate version: 3.0beta4
I'm using the Criteria API to issue a query similar to the following. I found out how to use the setResultTransformer() method so that it only returns a single Reservation object for each Reservation object, rather than one for each Item (a reservation can have items in my data model). This is working fine.
Code:
Criteria c = s.createCriteria(Reservation.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.createAlias("items", "i")
.add(Expression.like("i.name", itemName));
However, I'm wondering if maybe there is a more efficient or newer way to do this with the Hibernate 3.0 API since there is the new Projection API or what not. What I'm wondering is if there is a way to tell it to use a "distinct" in the SQL statement that it generates rather than presumably performing the filtering on the client side?