Using regular HQL I was able to get Hibernate to return a List of an object unmapped to the database by doing something along the lines of
List<MyUnmappedObject> result = (List<MyUnmappedObject>) session
.createQuery("select new MyUnmappedObject(obj1.field1, obj2.field1, obj2.field2) from MyFirstObject obj1 join obj1.obj2 obj2")
.list();
Now I am trying to do the same thing, but using Criteria. I know how to get a List using Projections, but is there any built-in support for new object creation using these results? Obviously I know that I can just parse the results and make the new object manually, but I'm trying to consolidate everything. I am currently using the following, but don't know how to incorporate this into direct object creation:
Criteria c = session.createCriteria(MyFirstObject.class, "obj1");
c.createAlias("obj1.obj2", "obj2");
c.setProjection(Projections.distinct(Projections.projectionList()
.add(Projections.property("obj1.field1")
.add(Projections.property("obj2.field1")
.add(Projections.property("obj2.field2")));
List<Object[]> result = c.list();
Any help would be appreciated.