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"
      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.)