This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Projection from inner join Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Projection from inner join" Watch "Projection from inner join" New topic

Projection from inner join

Siby George

Joined: Mar 22, 2011
Posts: 14
Hi All,

I am trying to project fields from 2 tables which are joined and also I need to order based on 2 columns, both from different tables.

The example SQL query is:

SELECT table1.col1, table2.col1, table2.col3 FROM table1 JOIN table2 ON table1.colm = table2.coln
WHERE table1.colm IN (1,2,3) ORDER BY table1.col1, table2.col1

I am trying this:


Criteria c = session.createCriteria(table2.class);
ProjectionList proList = Projections.projectionList();
// proList.add(;
List result = c.list();

Any example showing projection from two tables (joined) would do.

Siby George

Joined: Mar 22, 2011
Posts: 14
This can be achieved by using alias names for inner table like

criteria.createAlias(table1.table2, "table2");

and then using projection as,
I agree. Here's the link:
subject: Projection from inner join
jQuery in Action, 3rd edition