2 Replies Latest reply on Jun 27, 2005 7:00 PM by Emmanuel Bernard

    Multiple Lazy Levels

    Leos Urban Newbie

      I have entities:
      Invoice, every Invoice has InvoiceItems and every InvoiceItem has InvoiceItemSerialNumbers.
      All collections are accessed in lazy mode.

      Invoice - [LAZY] - InvoiceItem - [LAZY] - InvoiceItemSerialNumbers

      ( This is my test only, I use lazy on purpose. )

      In the SessionBean I have Query for accessing one invoice:

      Query q = manager.createQuery("from Invoice o left outer join fetch o.invoiceItems where o.invcode = :invcode");

      This works fine for items but serial numbers are not loaded and access to them ends with:

      org.hibernate.LazyInitializationException: \
      failed to lazily initialize a collection (cz.qds.demo2005v2.ebs.InvoiceItem.invoiceItemSerialNumbers) - no session or session was closed

      How to change Query to load serial numbers also?
      It is possible?

      What is preferred way - eager or lazy access?

      Thank you very much,