On Feb 4, 2007, at 8:37 AM, Andrus Adamchik wrote:

Hi Dain,

Just got some time to write a JPA/OpenEJB integration test following your example. Everything works except for one thing. Here is my sample code:

GeronimoTransactionManagerJTA11 tm = new GeronimoTransactionManagerJTA11();
        System.setProperty(
                Context.INITIAL_CONTEXT_FACTORY,
                LocalInitialContextFactory.class.getName());

new InitialContext().bind("java:comp/ TransactionSynchronizationRegistry", tm);

EntityManagerFactory factory = ... // init code for Cayenne JTA EMF JtaEntityManagerRegistry registry = new JtaEntityManagerRegistry(tm);

        tm.begin();

        EntityManager entityManager = new JtaEntityManager(
                registry,
                factory,
                new Properties(),
                false);


        SimpleEntity e = new SimpleEntity();
        e.setProperty1("XXX");
        entityManager.persist(e);
        tm.commit(); // Nothing is saved to the DB here

Now the problem...

According to the JPA spec, ch. 5.9.2, "When EntityManagerFactory.createEntityManager is invoked, the provider must create and return a new entity manager. If a JTA transaction is active, the provider must register for synchronization notifications against the JTA transaction."

So that's what Cayenne EMF does [1], [2] via TransactionSynchronizationRegistry.registerInterposedSynchronization (..). At a later time OpenEJB JtaEntityManager calls the same method on the registry to register a its own close operation, kicking out Cayenne EM callback. The end result is that the EntityManager is not flushed in "beforeCompletion" and nothing is saved to DB.

I suspect Geronimo TransactionImpl is to blame here. It only allows a single interposed synchronization. Is it a requirement of the JTA spec? (if it is, I couldn't find any mention of it). If everyone agrees with my assessment of the situation, I can submit a patch.

Thoughts?

Sounds like a Geronimo bug. Can you write a test case for the GeronimoTransactionManager and if it as you suspect, post a bug report to Geronimo JIRA?

Thanks,

-dain

Reply via email to