是否有可能在事务中使用多个持久单元,而不是XA? [英] Is it possible to use more than one persistence unit in a transaction, without it being XA?

查看:141
本文介绍了是否有可能在事务中使用多个持久单元,而不是XA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序需要使用(只读)指向不同数据库(不同的商业供应商)的几个不同的持久性单元。

我们没有在其中之一上启用2pc的预算(Sybase)。有没有办法在交易中使用这些交易,而不必成为XA交易?



我们使用的是Websphere 6.1,Sybase 12.5.3,Oracle 10g,Java EE 5和带有Hibernate Entity Manager的JPA。

更新:oracle PU每月更新很少1或2次,sybase PU为非常频繁地更新 - 每天多次。隔离绝对是后者关注的问题,两者之间的一致性并不是必须强制执行的。

解决方案

小心。 b $ b只读并不总是意味着2PC不适用。如果您有两个数据库,并且您同时读取但只更新一个数据库,则需要一个事务来保证一致的结果。假设您有一种方案可以读取数据库A,然后使用这些结果来读取和更新数据库B.如果您无法使用数据库A的事务,那么可能在您的操作处于活动状态时,您读取的数据数据库A可以由另一个应用程序读取和更新。在这种情况下,您可能会在数据库B中获得不一致的数据。



如果您确实正在读取两个数据库并且两者都不更新,您可能会认为分布式事务及其伴随的锁定是不必要的。尽管如此,也许不是。如果其他应用程序正在更新相同的数据库,则在这种情况下读取也可能不一致。这取决于您的要求和数据库的其他用户。



我建议阅读隔离级别,以便深入了解适用于所有持久存储(如数据库)的锁定,即使在读取操作期间也是如此。事务锁定可能是不必要的;例如,如果您正在处理的数据不会有效更改(不会由任何应用程序写入)。

也许这里有一个商业解决方案 - 与您的供应商协商,降低XA支持的价格并支付。随着经济的发展,你可能会得到一笔可以承受的交易。附注:我很惊讶你可以许可一个数据库而不是获得交易。我不知道有可能以这种方式授权Sybase。

Our application needs to use (read-only) a couple different persistence units pointing to different databases (different, commercial vendors as well).

We do not have the budget to enable 2pc on one of them (Sybase). Is there a way to use these in a transaction without it having to be an XA transaction?

We're using Websphere 6.1, Sybase 12.5.3, Oracle 10g, Java EE 5, and JPA with Hibernate Entity Manager.

Update: The oracle PU is updated rarely 1 or 2 per month, the sybase PU is updated very frequently -- many times per day. Isolation is definitely a concern for the latter, consistency between the two is not necessary to enforce.

解决方案

Careful.
Read-only does not always mean that 2PC does not apply. If you have two databases, and you read both but only update one, you need a transaction to guarantee consistent results. Suppose you have a scenario where you read database A, then use those results to read and update database B. If you fail to use a transaction with database A, then it is possible that while your operation is active, the data you have read from database A can be read and updated by another application. In this case you can get inconsistent data in database B.

If you truly are reading BOTH databases and updating neither, again you may think that a distributed transaction and its accompanying locking is unnecessary. Once again though, maybe not. You may get inconsistent reads in this scenario as well, if other applications are updating the same databases. It depends on your requirements and the other users of the database.

I would suggest reading up on isolation levels to get some insight into the locking that applies, even during read operations, for all durable stores like databases. Transactional locking may be unnecessary; for example it is unnecessary if you are dealing with data that effectively does not change (no writes by any app).

Maybe there is a business solution here - negotiate with your vendor to drop the price of XA enablement, and pay it. With the economy, you may get a deal you can afford. Side note: I am surprised that you can license a database and NOT get transactions. I was not aware that it was possible to license Sybase in that way.

这篇关于是否有可能在事务中使用多个持久单元,而不是XA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆