Is it possible to use more than one persistence unit in a transaction, without it being XA?
Asked Answered
G

2

3

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.

Glenglencoe answered 16/5, 2009 at 3:31 Comment(0)
G
3

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.

Gilliette answered 16/5, 2009 at 10:43 Comment(1)
Yes you raise very critical points. I clarified in the OP the isolation & consistency requirements of the two PUs. We're separately negotiating with the vendor. Note: obviously the database comes with transactions, but there's an added price tag for XA transactions -- welcome to the way sybase prices things.Glenglencoe
J
1

Atomikos TransactionsEssentials is a free, open source JTA/XA with connection pools for JDBC (and JMS).

One of its features is its added support for non-xa datasources. If readonly (your case) it is safe and easy to use our non-xa datasource to include your Sybase into a JTA transaction.

Best Guy

Jessamine answered 2/6, 2009 at 20:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.