4 Replies Latest reply on May 19, 2006 11:05 AM by horst21

    Persistence context scope and @EJB injection

    horst21

      Hello,

      I got a Problem with ejb3 stateless-session beans, @ejb injection and the persistence context.
      The setup is this:
      1) a stateless-session-bean that is a session-facade
      2) a stateless-session-bean that is a dao
      3) the session-fascade uses the dao (includes it with a @EJB annotation)

      no transaction annotations are used

      The problem is as follows:
      1) a call to the session-fascade is made
      2) the session fascade makes a call on the dao, in order to load an ejb3-entity-bean. this entity bean includes a collection that is lazy loaded.
      3) the entity bean is loaded an returned to the session fascade
      4) the session fascade tries to access the lazy-collection of the entity-bean -> this results in a org.hibernate.LazyInitializationException

      this looks like the persistent-context is not the same in the session-fascade and the dao. but since no transaction annotations are used in the session beans, I think the persistent context should be the same, shouldn't it?

      when i do not use the @EJB injection, but look up the dao in jndi myself, i can access the lazy-collection. I thought that these two option should result in the same behaviour, shouldn't they?

      thanks for your help, cheers.