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

    Multiple Lazy Levels

    leonell

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

      Schema:
      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,
      Leonell

        • 1. Re: Multiple Lazy Levels
          leonell

          Preferred way is lazy mode (I found it in Hibernate FAQ).

          Please, please some Hibernate Guru for answer how to load data when lazy collection are cascaded?

          Without its is lazy mode unusable and eager mode very slow for real application.

          Thanks.
          Leonell

          • 2. Re: Multiple Lazy Levels
            epbernard

            There are several ways, you can define the batch-size at collections and classes level and load the first element (not EJB3 standard) or use eager or use 2 collections fetches in your query (not EJB3 standard). It depends on you application