-->
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.  [ 2 posts ] 
Author Message
 Post subject: Criteria 2 table join problem
PostPosted: Thu Sep 18, 2008 11:51 am 
Newbie

Joined: Thu Sep 18, 2008 11:41 am
Posts: 1
Location: UK
Hi there, I've a problem with Hibernate 2 that I'm really struggling with

I've got the following tables/mappings:

LineOfBusinessDetails, which has a fk column of lineOfBusiness (into table LineOfBusiness)
LineOfBusiness which has a fk column of businessUnit (into table BusinessUnit
BusinessUnit table, which has name on it.

What I need to do, using the Criteria API is use an expression of the following type:

Code:
Criteria crit=Criteria.create(LineOfBusinessDetails.class);
crit.add(Expression.eq("lineOfBusiness.businessUnit.name","a name");


Apologies for the somewhat pseudo nature of the code.

However, I can't get the 2 level join to work correctly. I have tried all ways of creating alias etc but with no luck.

Can someone help please!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 8:48 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Try creating a new criteria on the secondary entity (BusinessUnit?), and apply the restriction on that one.


Code:
Criteria critLob=session.createCriteria(LineOfBusinessDetails.class);
Criteria critBu=critLob.createCriteria("businessUnit");
critBu.add(Expression.eq("name","a name");
return critBu.list();

_________________
Gonzalo Díaz


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

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.