-->
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.  [ 5 posts ] 
Author Message
 Post subject: how to use hibernate criteria to select from multiple tables
PostPosted: Thu Jan 14, 2010 8:29 pm 
Newbie

Joined: Sat Mar 18, 2006 1:27 am
Posts: 15
hi all,

i wonder how the criteria looks like when it comes to select records from two tables joined by the key

should look like this in sql:

Code:
select * from tableA a, tableB b
where a.id = b.fk_id
and .........


anyone?
if there isn't a method that allows to do so, is there another solution?

plz help


Top
 Profile  
 
 Post subject: Re: how to use hibernate criteria to select from multiple tables
PostPosted: Fri Jan 15, 2010 6:43 am 
Beginner
Beginner

Joined: Wed Jan 07, 2009 7:07 pm
Posts: 26
use Criteria.createAlias()


Top
 Profile  
 
 Post subject: Re: how to use hibernate criteria to select from multiple tables
PostPosted: Fri Jan 15, 2010 10:16 am 
Newbie

Joined: Sat Mar 18, 2006 1:27 am
Posts: 15
can you please give an example?


Top
 Profile  
 
 Post subject: Re: how to use hibernate criteria to select from multiple tables
PostPosted: Fri Jan 15, 2010 6:33 pm 
Beginner
Beginner

Joined: Wed Jan 07, 2009 7:07 pm
Posts: 26
Code:
getSession().createCriteria(A.class).createAlias("B","BAlias");


Along with this you have to specify the relation between A and B in hbm file.Where your specify the FK.

for e.g if A has many to one relation with B you can specify this in your hbm :

<many-to-one name="B" class="B" fetch="select">
<column name="FK_ID" />
</many-to-one>


Top
 Profile  
 
 Post subject: Re: how to use hibernate criteria to select from multiple tables
PostPosted: Fri Jan 15, 2010 6:40 pm 
Newbie

Joined: Sat Mar 18, 2006 1:27 am
Posts: 15
Thank you very much man! I will give it a shot shortly.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.