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?