-->
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 Query Inner Join Fetch
PostPosted: Mon Sep 09, 2013 10:57 am 
Newbie

Joined: Mon Sep 09, 2013 10:22 am
Posts: 1
I did a search through the forum on this issue finding at least half a dozen posts, but with no satisfactory explanation.

Simplified info to my specific project:
I am working on a Coldfusion project which uses hibernate 3.5.2-Final
I have a table dbo.resource which has a one-to-many relationship to dbo.resourceDetail

The problem seems to be that the Criteria Query does not support inner join whenever you want to fetch eagerly. You can do something like this:
Code:
Criteria c = sessionFactory.getCurrentSession().createCriteria(Resource);
c.createAlias("ResourceDetail", "rd", c.INNER_JOIN);
c.list();


And this produces SQL with a single select and an inner join just like you would think. The problem is that is fetches lazily, so whenever you want to actually access resourceDetail, you get the N+1 selects problem. The solution is:
Code:
c.setFetchMode("ResourceDetail", FetchMode.JOIN);
c.createAlias("ResourceDetail", "rd", c.INNER_JOIN);
c.list();


But this forces an outer join. I need to do an inner join. I need to fetch all the data at once. And I'd much rather use a Criteria Query.

Using HQL is an obvious solution to this problem, but I like Criteria Query much better, because it looks nicer and its more programmatic. So it appears the Criteria Query was simply written without the ability to fetch with inner joins (which seems crazy to me), but are there any work arounds that any knows about? Any assistance would be greatly appreciated.


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.