您可以创建自己的 JTA 事务吗?
我正在从网络服务将大量数据加载到数据库中。我使用 eclipslink 来实现持久性并在 glassfish 3.0 上运行该应用程序。我在测试数据集上遇到了一些问题,因为存在一些外键约束违规。我对违规行为表示同意,如果数据不完整,我不想要该数据。然而,我的问题是在容器中抛出异常。然后,这将我的事务标记为回滚,然后我根本没有得到任何数据。
我想继续使用 JTA,但不确定我是否可以实现我想要实现的目标,即创建我自己的 JTA 事务,以便我可以控制它的提交时间等。我不确定这是否是一个好主意,但我觉得这样做可能会破坏使用 JTA 的一些好处。
那么是否可以得到JTA交易呢?
I am loading a large set of data into a database from a webservice. I am using eclipslink for persistence and running the application on glassfish 3.0. I run into problems on my test data set in that there are a few foreign key constraint violations. I am fine with the violation, I do not want that data if it is not complete. My problem however comes in that the exception is thrown in the container. That then marks my transaction for a rollback, and I get no data at all then.
I would like to continue using JTA but am not sure if I can do what I want to achieve, and that is create my own JTA transaction so I can control when it commits,etc. I am not sure if that is a good idea though as I feel by doing so I may be destroying some of the benefits of using JTA.
So is it possible to get a JTA transaction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在会话 bean 的方法中进行数据库工作。将该方法注释为:
它将被赋予自己的事务。外部事务在执行其操作时将被暂停。
Do the database work in a method of a session bean. Annotate that method with:
It will be given its own transaction. The outer transaction will be suspended while it does its stuff.
http://wiki.eclipse.org/Using_Advanced_Unit_of_Work_API_%28ELUG%29#Integrating_the_Unit_of_Work_with_an_External_Transaction_服务强文本**
阅读如何使用外部事务服务获取工作单元。显然,您可以通过查询容器 JNDI 中的 UserTransaction 来获取 UserTransaction 和/或启动自己的 UserTransaction
http://wiki.eclipse.org/Using_Advanced_Unit_of_Work_API_%28ELUG%29#Integrating_the_Unit_of_Work_with_an_External_Transaction_Servicestrong text**
Read How to Acquire a Unit of Work with an External Transaction Service. Apparently you can snatch the UserTransaction and/or start your own by querying the container JNDI for UserTransaction