2 Replies Latest reply on May 24, 2006 11:42 AM by martinso

    Nested JOIN FETCH

      Hi,

      Let's say I have three Entity classes A, B and C and the relations A 1:n B 1:n C. The collections are named A.bs and B.cs. No relation is marked with fetch=EAGER in the @OneToMany annotations.

      With the query

      SELECT DISTINCT a FROM A a JOIN FETCH a.bs WHERE a.id = 1

      I get the Bs eagerly loaded as expected in A.

      Now, is there a way to alter this query to also include the eager loading of the Cs in the B?

      The whole point is to avoid the fetch=EAGER in the @OneToMany annotations.

      Regards

        • 1. Re: Nested JOIN FETCH
          echon

          from A a left join fetch a.bs as b left join fetch b.cs as c where a.id=1
          why do you use a normal join and no left join? In your case only results As in the scalar where A has some Bs.

          • 2. Re: Nested JOIN FETCH

            Thank you, echon! Just what I wanted.

            And you're right, it should definately be a LEFT JOIN FETCH there.