This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Spring & JTA

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're very welcome Gavin.
 
Let nothing stop you! Not even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!