aspose file tools*
The moose likes Object Relational Mapping and the fly likes Criteria query select specific columns from several entities Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Criteria query select specific columns from several entities" Watch "Criteria query select specific columns from several entities" New topic
Author

Criteria query select specific columns from several entities

orm newbie
Greenhorn

Joined: Jul 25, 2013
Posts: 1
Hi,
I have an entity A, which has entity B and B has entity C : A -> B -> (collection of C)
I want to form a criteria query and select all columns from A, all columns from B and specific columns from C.
I wrote a query using Criteria and Projections, but its querying only the specified columns of entity C and none from A or B.

Here is my query :
Criteria crit = s.createCriteria(A.class, "tableA")
.add(Restrictions.eq("Id", 100))
.createAlias("b", "tableB")
.createAlias("tableB.c", "tableC");

ProjectionList proList = Projections.projectionList();
proList.add(Projections.property("tableC.prop1"));
proList.add(Projections.property("tableC.prop2"));
proList.add(Projections.property("tableC.prop3"));
crit.setProjection(proList);
crit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

Can somebody tell me how can I tune this query ?
Thanks much in advance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Criteria query select specific columns from several entities