I have an EJB3 MDB deployed in JBoss (container transaction, transaction Required for onMessage), this MDB uses injected EntityManager (JTA one injected with @PersistenceContext type=Transaction in MDB) in order to update a same value as property for 2 differents entities (mapped on 2 differents tables in PostgreSQL database).
If I check by hand in database (with psql client), everything is coherent as the value is the same in the 2 involved tables.
I also trigger MDB from a standalone JUnit TestCase (runned by maven). In order to be aware in this test that MDB transaction is successfully commited, I register a Synchronisation instance in MDB, and in afterCompletion method I send back to the JMS confirmation message (as TestCase is also a MessageListener to be notified).
In this case, TestCase is properly notified that MDB work is completed, but when it try to check value using its own EntityManager (as TestCase is outside JBoss), sometimes (not always unluckily) this value is ok in one table/entity but not in the other.
I've tried various hibernate settings (isolation level, hibernate.transaction.factory_class, hibernate.transaction.manager_lookup_class), but trouble still occurs.
EntityManager used by TestCase is a RESOURCE_LOCAL one.
JBoss 5.1.0.GA / sun jdk 1.6 / PostgreSQL 8.x / Hibernate EntityManager 3.4