0 Replies Latest reply on Jun 5, 2006 6:40 AM by daniel jarrett

    (Lazy) Fetch using EJBQL

    daniel jarrett Newbie

      I am wondering if there is any neater way to do the following.

      s = (Session) em.createQuery(
       "SELECT DISTINCT s " +
       "FROM Session as s " +
       "WHERE s.sessionId = :sessionId")
       .setParameter("sessionId", sessionId)
       .getSingleResult();
       for(SessionSupplier sessionSupplier:s.getSessionSuppliers())
       {
       sessionSupplier.getSessionSupplierLocations().size();
       }
      


      the SessionSupplier entity has a many relationship to one session, and the sessionSupplierLocation is the same to SessionSupplier. They both have a fetch type of LAZY from their parent objects.

      I am basically wondering if i can initialize these child entities through the EJBQL?

      I tried using something like

      s = (Session) em.createQuery(
       "SELECT DISTINCT s " +
       "FROM Session as s " +
       "LEFT JOIN FETCH s.sessionSuppliers as ss " +
       "LEFT JOIN FETCH ss.sessionSupplierLocations as ssl " +
       "WHERE s.sessionId = :sessionId")
       .setParameter("sessionId", sessionId)
       .getSingleResult();