管理交易的最佳方式
我有基于 JBoss 和 Hibernate 的系统。 我需要处理两个长操作。操作的时间可能比事务的超时时间还要长。 它的操作是在两个不同的事务中持久保存多对多实体。 如果出现问题,在此操作期间,我应该回滚事务的所有更改。
解决它的最佳方法是什么?
我认为,最好的方法是将所有操作合并到一个事务中,但这需要设置很长的事务超时,这对于我们的系统来说是不可接受的。
在这种情况下,许多交易的管理是否更好?我该怎么做呢?
I've the JBoss and Hibernate based system.
And I need to process two long operations. Operations can be probably longer than transaction's timeout.
It operations are persists many-many entities, in two different transactions.
And if something goes wrong, during this operations, I should rollback all changes of the transactions.
What's the best way to resolve it?
I think, the best way is merge all operations to one transaction, but it requires to set LOng transaction timeout, and it unacceptable for our system.
Is the managing of many transactions better in this situation. And how can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 JTA 服务器(事务协调器)通过 XA 事务分多个步骤执行事务吗? 这篇文章有一些粉丝 -寻找一些可能适合您的开源软件。
XA 事务 允许您执行一系列较小的操作并提交或回滚他们一击。尝试用谷歌搜索“hibernate xa transactions”。大多数现代 RDBMS 平台(MySQL 5.x、PostgreSQL、SQL Server、Oracle、DB2、Sybase 等)都支持 XA 事务。
Can you use a JTA server (transaction coordinator) to do the transaction in multiple steps with XA transactions? This posting has a bit of fan-out to a couple of open-source ones that might work for you.
XA transactions allow you to do a bunch of smaller operations and commit or roll back them in one hit. Try googling for 'hibernate xa transactions'. Most modern RDBMS platforms (MySQL 5.x, PostgreSQL, SQL Server, Oracle, DB2, Sybase etc.) support XA transactions.
使用一笔交易是好的、健壮的等等。再次尝试说服您的管理员;-)
否则,我可以想到:
update ... where ...
)。这应该比完全插入快得多,因此事务应该足够短。Using one transaction is good, robust and so on. Try again to convince your administrator ;-)
Otherwise, I can think of:
update ... where ...
). This should be much faster than the full insertion was, so the transaction should be short enough.我必须在 JPA 中做类似的事情(通过 hibernate)。我在 N 笔交易而不是 1 笔大交易中进行了操作。此操作很少运行 - 这是一项自动化作业 - 因此没有用户在网页上等待结果。
您预计交易需要多长时间?您预计用户要等待多长时间?您预计此操作发生的频率是多少。可能是你的要求不明确。
I had to do something similar in JPA (via hibernate). I did the operation in N transactions rather than 1 big transaction. This operation ran rarely - it was an automated job - so there was no user waiting at a web page for a result.
How long do you expect the transaction to take? How long do you expect the user to wait?? How often do you expect this operation to occur. Maybe you're requirements are not clear.