-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Criteria API multiple tables join
PostPosted: Thu Jan 17, 2013 4:46 pm 
Newbie

Joined: Thu Jan 18, 2007 11:28 am
Posts: 5
Hi all,
I have 3 tables that I need to join: TableA, TableB and TableC. TableA is totally standalone, but TableB and TableC are related via one-to-many mapping (yay!)
Here's my working join using Criteria API.
DetachedCriteria tableBnCJoin= DetachedCriteria.forClass(TableB.class);
tableBnCJoin.setProjection(Projections.property("tableBEmployeeId"));

Criteria tableACriteria = getSession().createCriteria(TableA.class);
criteria.add(org.hibernate.criterion.Property.forName("tableAEmployeeId").in(tableBnCJoin));
criteria.setProjection(Projections.projectionList()
.add(Projections.distinct(Projections.property("tableAEmployeeId")))
.add(Projections.property("tableAEmployeeName")));

That all works well, but now I need to return TableCEmployeeAddress from TableC.
How do I add the column TableCEmployeeAddress returned? Do I add the projection to tabBnCJoin criteria or tableACriteria?



Thank you so much in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.