Havent tried it but another way could be
session.createCriteria(Parent.class)
.createAlias("children", "child")
.returnMaps()
.list();
Each list entry is a map with containing the parent and the child entries (each child in a separate entry but with the same parent)
Ananasi wrote:
I think you can do it with projections. e.g.
Code:
List results = session.createCriteria(Parent.class, "parent") // Criteria on the parent class
.createAlias("children", "child") // Alias the children collection
.setProjection( Projections.projectionList() // Create projections for each column in result
.add( Projections.property("parent.property1"), "parentProperty1" )
.add( Projections.property("parent.property2"), "parentProperty2" )
.add( Projections.property("child.property1"), "childProperty1" )
.add( Projections.property("child.property2"), "childProperty2" )
)
.addOrder( Order.asc("parentProperty1") ) // When you alias the projections, you can
.addOrder( Order.asc("childProperty2") ) // refer to them later
.list();