views:

323

answers:

1

I am trying to integrate together JOTM and Hibernate EntityManager to test my EJBs in a transactional manner environment but out-of-container.

My test looks like the following:

  1. Start JOTM
  2. Put JOTM's UserTransaction into JNDI
  3. Create and configure StandardXADataSource
  4. Put the DataSource into JNDI
  5. Configure hibernate and create EMF
  6. Create an EM
  7. Begin a transaction
  8. Join the transaction in EM
  9. Store an entity
  10. Verify it is stored
  11. Rollback the transaction
  12. Check the database for the count of records
  13. Tear everything down

Here is what my code looks like: http://pastebin.com/m22a9f6b

Here is the logging output: http://pastebin.com/m6da9383a

The test fails on step 12 (line 121).

As you can see, even though I have roll-backed the transaction, there is a record in the DB. Seems like transactions where not used at all and the record got through into the db.

Do you have any ideas how this could be happening and how to fix it?

A: 

I figured out I need to provide my own implementation of ConnectionProvider that would return XAConnection instead of simple connections. This way transactions seem to work

artemb
I am having the same kind of issues but in a spring context.http://stackoverflow.com/questions/1519968/spring-jta-jpa-unit-test-rollback-not-working Can you help ?
Michel