3 Replies Latest reply on Mar 13, 2012 5:20 AM by maximilien

    EJB Remoting and lazy loading

    maximilien

      Hi,

       

      I'm using ejb remoting to make invocations from a remote server.

      The remoting call works great but i wonder if it is possible to use lazy loading on collections.
      When i try i got

      org.hibernate.LazyInitializationException: could not initialize proxy - no Session

      Is it a configuration problem or it's not possible to propagate the persistence context ?

       

      Best regards,

        • 1. Re: EJB Remoting and lazy loading
          smarlow

          This lazy initialization error will occur when the persistence context has gone out of scope before the lazy fetch has occurred.  You shouldn't try to propagate the EntityManager itself but having the remote invocation return detached entities should be fine. 

           

          You could make the collection not be lazy but that typically isn't good for performance.

          • 2. Re: EJB Remoting and lazy loading
            maximilien

            Hi Scott,

             

            I don't know if i understand you correctly.

            I don't try to propagate the EntityManager, i do something like that

             

            On Client Server

              HystoryService service = (HistoryService) context.lookup("ejb:" + "myapp" + "/" + "myejb" + "/" + "" + "/" + "HistoryServiceImpl" + "!" + org.myapp.ejb.HistoryService.class.getName());

              Order order = service.getOrder("123456");

              order.getItems();

             

            And i'd like the proxy makes the lazy loading when i call the getItems.

             

            As you said i could make the collection not be lazy but that typically isn't good for performance.

            If i understand you correctly

             

            You shouldn't try to propagate the EntityManager itself but having the remote invocation return detached entities should be fine.

            what i do should work and it's more a problem of configuration, that's it ?

            • 3. Re: EJB Remoting and lazy loading
              maximilien

              After some research i realized that remote lazy loading on entities should be possible throught custom hibernate proxy attached to remoting channel but is quite complex to do and is not a best practice.

              I've found another architecture for my application that is more standard.

               

              Best regards,