Joarder Kamal
Joarder Kamal

Reputation: 1397

How to use JPA and JTA together with a transaction manager?

I have an existing client-server project which uses plain JDBC to communicate with a single MySQL instance. Now I would like to extend it to support multiple (sharded) MySQL instances using any JPA implementation and with the help of JTA implementation that supports XA transactions.

My question is how should I proceed? After several hours of Googling what I understand I may not able to use JTA implementations without any application server container, is it true?

For my purpose I would be happy if the application logics could be abstracted using any ORM layer - a JPA implementation (like EclipseLink Partition or OpenJPA Slice) and then using a transaction manager (like BTM) to execute the XA transactions providing ACID guarantees over the underlying set of MySQL instances.

So far I tried the video tutorial in YouTube (https://www.youtube.com/watch?v=Vmr6GAlbG10) experimenting with EclipseLink and a single db instance. Now I'm planning to extend it over multiple instances but not sure how.

Any kind suggestions, links and guidelines would be very helpful. I'm kind of new to this so accept any inconvenience if I misunderstood anything. Thanks.

Upvotes: 3

Views: 3558

Answers (2)

Alex Chernyshev
Alex Chernyshev

Reputation: 1745

You can use standalone JTA transaction manager like Atomikos http://www.atomikos.com/ or SimpleJTA http://simplejta.sourceforge.net/ completely outside of any container.

More about standalone JTA managers: What is a good open source Java SE JTA TransactionManager implementation?

Also it's possible to use popular JPA implementations as standalone with combination with standalone JTA (what you asked). Here is sample for Atomikos and Hibernate http://www.atomikos.com/Documentation/HibernateThreeStandalone

But this is not great way to use such technologies and you have any chances and time - move to normal three-tier architecture with application server.

Upvotes: 1

V G
V G

Reputation: 19002

It is also possible to use JTA in the context of a Spring application.

Besides, you COULD use it in the context of your own application without any frameworks, but it is pretty complicated, as you will have to control what/when/where is injected and how the called method returned (with Exceptions or without). But of course, it really depends on what exactly you want to use from JTA: transaction propagation or simply using different databases in the same JTA transaction.

So, my suggestion is to use Spring, if you do not want to use an application container (Java EE).

Upvotes: 0

Related Questions