2 Replies Latest reply on Nov 2, 2007 3:24 PM by Clint Popetz

    Problem synchronizing managed-persistence-context

    Clint Popetz Apprentice

      I'm experiencing the following problem with seam 2.0.0CR3, hibernate 3.2.5ga, hibernate EM 3.3.1 GA. I'm running with the embedded jboss EJB3 container that's packaged with seam, so I'm not sure of its version number, but I don't think this behavior is specific to the embedded container.

      I have a managed-persistence-context and a factory to inject its session delegate, almost straight out of the manual:

      <persistence:managed-persistence-context name="discussionEM"
      auto-create="true"
      persistence-unit-jndi-name="<the path to my factory>"/>

      <factory name="discussionSession" auto-create="true" value="#{discussionEM.delegate}"/>


      Here's the use-case. A non-transactional method calls a method on a SFSB bean that has the discussionSession injected with @In. When that happens, the container sets up a transaction, and when discussionEM is @Unwrapped it calls joinTransaction, the entity manager joins the transaction, and everything is cool. That method returns, and the transaction is committed and removed. Now my non-transactional caller calls _another_ method on the same SFSB. This time, the container sets up a transaction, but @Unwrap is never called on discussionEM, because the discussionSession is found in the event context, and here is no component named "discussionSession" (since it's a factory), so no unwrap method is called, so no synchronization happens.

      So is there something I'm doing wrong? My feeling is that if ManagedPersistenceContext is going to do important things in @Unwrap, then @Unwrap needs to be called on every injection, which it's not (at least in this case.)

        • 1. Re: Problem synchronizing managed-persistence-context
          Clint Popetz Apprentice

          Doh, I see. I have to make the stateless, which the example in the docs did (though it didn't describe why it did so.)

          I still think it's a little strange to have the @Unwrap annotation being used in that way. It would be better to have an @UponInjection annotation, which is called regardless of whether an unwrap is needed. And factory methods should call @UponInjection upon their delegates, if the latter are also components.

          Just random musings...you guys have thought about this more than I have :)

          • 2. Re: Problem synchronizing managed-persistence-context
            Clint Popetz Apprentice

             

            "cpopetz" wrote:
            Doh, I see. I have to make the <factory> stateless, which the example in the docs did (though it didn't describe why it did so.)
            :)


            My "make the stateless" should have been "make the factory stateless" but because I wrapped "factory" in brackets it disappeared.