This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Spring & JTA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring & JTA" Watch "Spring & JTA" New topic
Author

Spring & JTA

Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Hi all,
Is my day for questions. I got landed with a web app project, and decided to use spring MVC.

I liked its "layered" approach so I could get teh app up and running and then worry about expaniding it out with things like Transactions, Security and perhaps using ORM.

However, if all I need to do in a single DB environment is:


If i am understanding this layered/modulor approach right, I shouldnt have to do too much to update my code to take advantage of another service (JTA in this case) but i have so far only seen the above entry in the jPetStore example, so I feel I am missing something, it cant be that easy.

G
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi,

I suppose that you'd like using declarative transactions (via AOP) with Spring. You may need then to read about the Spring transaction management here:

http://www.springframework.org/docs/reference/transaction.html

In a nutshell you need to define your transaction manager to be JTA compatible. If you�re using WAS it might look something like this:



For most of the app servers using only the JtaTransactionManager should be quite enough.

Now assuming you have a controller bean that uses a DAO (implemented using an ORM tool like Hibernate) that updates two different databases, which should happen within the same transaction:



The trick here is that you�ll map the requests to a proxy bean ( removeTransactionController), which will actually do the transaction management for you (Spring uses the cglib api in order to build this proxy bean at runtime):



If your app doesn�t use global transactions, then using the HibernateTransactionManager could be your best choice with spring-hibernate applications:



Basically this is how it works.
Regards.


I think, therefore I exist -- Rene Descartes
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Thanks for the detailed answer.

It sounds like I wont be needing JTA for my app then, as I only have one DB on one server to deal with.

G
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
You're very welcome Gavin.
 
 
subject: Spring & JTA
 
Similar Threads
Setup JTA in JBOSS(5.0)
P6spy does not create spy.log for stand-alone Java program
handling ContextSource & DataSource Transaction using @Transactional annotation.
Jboss/JTA/spring "No JTA TransactionManager found"
Spring - Connection Problem in some Unit Tests