-->
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.  [ 7 posts ] 
Author Message
 Post subject: inner join fetch in criteria api
PostPosted: Thu May 11, 2006 6:51 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 11:51 pm
Posts: 22
Hi ,

There is is inner join fetch in Hibernate Reference Doc 3.1.3 , pg143.

Code:
from Cat as cat inner join fetch cat.mate left join fetch cat.kittens


How to do it using Criteria api ?

moon


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 7:11 am 
Newbie

Joined: Wed Nov 23, 2005 5:01 am
Posts: 15
Hi,

You can do that with the following:

Quote:
List result=(List) session.createCriteria( Cat.class )
.setFetchMode("mate", FetchMode.EAGER)
.setFetchMode("kittens", FetchMode.EAGER).list()


I hope this help

Calin


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 10:32 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 11:51 pm
Posts: 22
this will get two outer joins , right ?
what l want is "inner join fetch" , not "left join fetch" , or l miss something ? :)

moon


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 6:26 pm 
Newbie

Joined: Wed Nov 23, 2005 5:01 am
Posts: 15
Hi,
Sorry, was my mistake. Yes you have right it will perform to outer join.

I don't think that you can obtain the same result with Criteria API. It is known that there are differences between the HQL and Criteria API. The HQL is more flexible.

_________________
I hope this help.
Calin


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 12, 2006 7:23 pm 
Beginner
Beginner

Joined: Mon Sep 27, 2004 11:51 pm
Posts: 22
:) .... l use criteria api mostly because of *dynamic query* , if l cannot do it in criteria api , then l have to code a lot .....

moon


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 13, 2006 4:21 pm 
Newbie

Joined: Tue Feb 21, 2006 10:34 am
Posts: 7
from Hibernate 3.1.3 you can do following

Code:
List result = session.createCriteria(Cat.class)
.createAlias("mate", "m", CriteriaSpecification.INNER_JOIN)
.createAlias("kittens", "k", CriteriaSpecification.LEFT_JOIN).list()

Is it what you are looking for?
(note that online docs available on hibernate web page shows old javadoc and this function is not described there, download latest release - proper javadoc is included)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 6:50 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
The above doesn't do an eager fetch as far as I know.


We seem to come to the conclusion that "left join fetch" works in criteria, but "inner join fetch" doesn't, at least in hibernate 3.2.5.ga. It just ignores the setFetchMode part when doing an inner join.

_________________
http://www.ohloh.net/accounts/ge0ffrey


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