1 Reply Latest reply on Mar 25, 2008 4:56 AM by mars1412

    Multiple entity level join fetch

    Dan Dosch Newbie

      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