5 Replies Latest reply on May 29, 2008 1:35 AM by infinity2heaven

    Multi level join fetch

    norad2

      Say I have three entities, Owner, Cat, Kitten


      
      @Entity
      
      public class Owner {
      
           private Integer ownerId;
      
           private Set<Cat> cats = new HashSet<Cat>(0);
      
           .
      
           .
      
           .
      
      }
      
      
      @Entity
      
      public class Cat {
      
           private Integer catId;
      
           private Set<Kitten> kittens = new HashSet<Kitten>(0);
      
           .
      
           .
      
           .
      
      }
      
      
      @Entity
      
      public class Kitten {
      
           private Integer kittenId;
      
           .
      
           .
      
           .
      
      }
      
      



      I want to be able to run one query that will join fetch all owners, cats and kittens



      If I wanted to get all cats for all owners I could simply make the query


      select o from Owner o join fetch o.cats




      I was trying to get the kittens at the same time with a query like this:


      select o from Owner o join fetch o.cats join fetch o.cats.kittens

      but that doesn't work.


      What would be the proper syntax to go multiple levels deep in a join fetch?


      Thanks,
      Dan