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:
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 queries are made. I.E. it seems like the recursion is not working.
I have also tried just a JOIN FETCH (which I think does an inner join fetch) with no luck.
Any ideas?