Hi guys,
Ok, i've now committed my "addons" on Gavins great work on the projection API in Criteria.
I have added a ToBeanResultTransformer which makes it possible to do stuff like:
public class StudentDTO { ... public String courseDescription; public String setStudentName(String sn) { .. }; }
List resultWithAliasedBean = s.createCriteria(Enrolment.class)
.createAlias("student", "st")
.createAlias("course", "co")
.setProjection( Expression.projection()
.add( Expression.property("st.name"), "studentName" )
.add( Expression.property("co.description"), "courseDescription" )
).setResultTransformer(new AliasToBeanResultTransformer(StudentDTO.class))
.list();
And the result will contain instances of StudentDTO (this is similar to the concept of setResultClass() in e.g. JDO2)
Note: This also works for non-projection queries.
There is one caveat with having resulttransformers on projection and that is
Criteria defaults to use Criteria.ROOT_ENTITY as transformer and this result
in just being returned the first element of a possible projection.
Should we automatically set Criteria.PROJECTION_RESULT as resulttransformer when calling setProjection ?
Or should the user explicitly state what she wants ?
-- Max Rydahl Andersen callto://max.rydahl.andersen
Hibernate [EMAIL PROTECTED] http://hibernate.org
JBoss Inc [EMAIL PROTECTED] http://jboss.com
------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl _______________________________________________ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel