Hibernate EntityManager + JOTM:不使用交易
我正在尝试将 JOTM 和 Hibernate EntityManager 集成在一起,以在事务方式环境中但在容器外测试我的 EJB。
我的测试如下所示:
- 启动 JOTM
- 将 JOTM 的 UserTransaction 放入 JNDI
- 创建并配置 StandardXADataSource
- 将数据源放入 JNDI
- 配置休眠并创建 EMF
- 创建 EM
- 开始事务
- 在 EM 中加入事务
- 存储实体
- 验证已存储
- 回滚事务
- 检查记录计数的数据库
- 撕毁所有内容
这是我的代码的样子: http://pastebin.com/m22a9f6b
这是日志输出: http://pastebin.com/m6da9383a
测试在步骤 12(第 121 行)失败。
正如你所看到的,即使我已经回滚了事务,数据库中还是有一条记录。似乎根本没有使用事务并且记录已进入数据库。
您知道这种情况是如何发生的以及如何解决吗?
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:
- Start JOTM
- Put JOTM's UserTransaction into JNDI
- Create and configure StandardXADataSource
- Put the DataSource into JNDI
- Configure hibernate and create EMF
- Create an EM
- Begin a transaction
- Join the transaction in EM
- Store an entity
- Verify it is stored
- Rollback the transaction
- Check the database for the count of records
- 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现我需要提供自己的 ConnectionProvider 实现,它将返回 XAConnection 而不是简单的连接。这样交易似乎就可以进行
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