简体   繁体   English

Hibernate EntityManager + JOTM:不使用事务

[英]Hibernate EntityManager + JOTM: transactions are not used

I am trying to integrate together JOTM and Hibernate EntityManager to test my EJBs in a transactional manner environment but out-of-container. 我正在尝试将JOTM和Hibernate EntityManager集成在一起,以在事务方式环境中但不在容器中测试我的EJB。

My test looks like the following: 我的测试如下所示:

  1. Start JOTM 启动JOTM
  2. Put JOTM's UserTransaction into JNDI 将JOTM的UserTransaction放入JNDI
  3. Create and configure StandardXADataSource 创建和配置StandardXADataSource
  4. Put the DataSource into JNDI 将数据源放入JNDI
  5. Configure hibernate and create EMF 配置休眠并创建EMF
  6. Create an EM 创建一个EM
  7. Begin a transaction 开始交易
  8. Join the transaction in EM 在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 这是我的代码: http : //pastebin.com/m22a9f6b

Here is the logging output: http://pastebin.com/m6da9383a 这是日志记录输出: http : //pastebin.com/m6da9383a

The test fails on step 12 (line 121). 测试在步骤12(第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? 您是否有任何想法如何发生以及如何解决?

I figured out I need to provide my own implementation of ConnectionProvider that would return XAConnection instead of simple connections. 我发现我需要提供自己的ConnectionProvider实现,该实现将返回XAConnection而不是简单的连接。 This way transactions seem to work 这样交易似乎有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM