1 Reply Latest reply on Aug 27, 2008 8:34 AM by Rami Zilberstein

    EJB3 transaction / lazy loading issue

    Rami Zilberstein Newbie


      got an entity with a few lazy collections in it.
      also got a stateless session bean that uses this entity in an ejb method. the method does no changes to the entity, only reads the entity's data and returns it.

      now if i use:


      i get the notorious lazy load exception problem when i try to invoke getters of the entity's lazy collection. so i remove the attribute at all or use the
      attribute instead.

      the thing is that i then see in the server log that hibernate is invoking an update query on the entity. the query updates all the entity's fields (not the lazy collections) by primary key field as well as version field.
      the update SQL together with commit takes around 20-40 milliseconds which is just too much for me.

      why is the update being performed?
      is there a way to prevent it (since i know for sure i do not need it)?
      is there a way to enjoy lazy load without opening a transaction? (a sort of a read only trx..)