-->
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: Recursive fetch join not recursively fetching all children
PostPosted: Mon Mar 19, 2012 5:06 pm 
Beginner
Beginner

Joined: Mon Dec 21, 2009 3:43 pm
Posts: 24
I have a directory type structure represented as entities, i.e. think Directory entity and File entity.

The Directory entity has a collection of File entities and a collection of Directory entities.

I want to get the root directory and 'pre load' all directories and there files.

I am trying:
Code:
String queryString = "SELECT DISTINCT d FROM " +
   Directory.class.getSimpleName() +
   " d LEFT JOIN FETCH d.files LEFT JOIN FETCH d.directories child LEFT JOIN FETCH child.files LEFT JOIN FETCH child.directories WHERE f.root = :isRoot);
Query query = em.createQuery(queryString);
query.setParameter("isRoot", true);

Directory dir = (Directory) query.getSingleResult();


The query works it just does not pre load everything. I get all of the root directories and the root files, but when I start going into the sub directories and get the files, hibernate starts to hit the database, telling me that not everything was fetched. I.E. it seems like the recursion is only going to a certain depth.

I am using Oracle 11g. Is there a limit to the number of joins in oracle? Is there a join 'depth' somewhere that I need to set before making the query?


Top
 Profile  
 
 Post subject: Re: Recursive fetch join not recursively fetching all children
PostPosted: Tue Mar 27, 2012 8:05 pm 
Beginner
Beginner

Joined: Mon Dec 21, 2009 3:43 pm
Posts: 24
The problem was with calling

Code:
query.getSingleResult();


Even though I am selecting DISTINCT to indicate to hibernate to fetch all the LAZY loaded children into one object you cannot ask for a single result.

Code:
query.getResultList();


Is what I needed


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.