[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Spring Transaction Management.

Posted on 2005-04-23
11
Medium Priority
?
1,135 Views
Last Modified: 2013-12-03
Hello all,

     I found this para in the spring documentation.

Global transactions have a significant downside. Code needs to use JTA: a cumbersome API to use (partly due to its exception model). Furthermore, a JTA UserTransaction normally needs to be obtained from JNDI: meaning that we need to use both  JNDI and JTA to use JTA. Obviously all use of global transactions limits the reusability of application code, as JTA is normally only available in an application server environment.

    Does this mean that we can use spring  and have the application code (using JTA) run on Web-Servers as well (like Tomcat) ??

If Yes then my next question is how will the Tomcat understand JTA API ?  Doesnt it need a J2EE (or EJB) container to support JTA ?

Thank You,
0
Comment
Question by:letsbedecent
  • 6
  • 5
11 Comments
 
LVL 15

Expert Comment

by:aozarov
ID: 13850940
Spring supports both JTA and local jdbc transaction managers, though Spring normally favours the latter.

>> Does this mean that we can use spring  and have the application code (using JTA) run on Web-Servers as well (like Tomcat) ??
Yes. you are basically using Spring transaction manager.

>> how will the Tomcat understand JTA API ?
It will not tomcat as web container is not an XA resource.
In what respect to you want it to integrate?
If you are talking about DB interaction then you would probably want to use Spring DataSource instead of Tomcat
(so it will be included in your transactions). Also for that purpose Hibernate integrate pretty well (instead of doing plain jdbc).
0
 

Author Comment

by:letsbedecent
ID: 13850955
Suppose that an application uses JTA api for transaction management, now if we want to run it on Tomcat using spring can we do that ??      
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13851049
I think so.
<bean id="transactionManager"
    class="org.springframework.transaction.jta.JtaTransactionManager"/>
This is a JTA manager which suppose to handle any XA resource.
You wil probably need to change your application with they way you obtained so far the transaction manager.
Is your application using the JTA api directly or is it depended on a transactional DS?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:letsbedecent
ID: 13854204
My application does not use the api directly, it uses container managed transactions on weblogic, which means weblogic uses JTS to maintain the transactions for my application right. Moreover, JTS is capable of handling distributed transactions,

So, if i use Springs datasource, will it be able to handle the distributed transactions ??
0
 

Author Comment

by:letsbedecent
ID: 13854238
Basically here is what i am trying to understand,

Using weblogic or any application server with container managed transactions we can handle distributed transactions with code that is very neat (nothing about the transactions).  The application servers acheive this by their own implementation of the JTS spec.  

Now, if we are using Spring over Hibernate(for example) can we have the Spring to handle the distributed transactions ??  

If yes, then does it mean that spring implements JTS ??

Please let me know how it works
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13854327
>> So, if i use Springs datasource, will it be able to handle the distributed transactions ??
Yes, as long as you are using the JtaTransactionManager and not the local transaction manager such as DataSourceTransactionManager.

>>  (nothing about the transactions). The application servers acheive this by their own implementation of the JTS spec.  
That is not totaly correct. Yes, application servers come with JTA compiler transaction manager (so does spring), but you still need to configure your resources
and application to use it. You do that when you define an XA datasource and you do that in your code programatically or/and in your ejb-xml configuration file when you define
how your are beans involved in the transaction (start a new one, suspend the current one, use the current one, ...)

>> Now, if we are using Spring over Hibernate(for example) can we have the Spring to handle the distributed transactions ??  
Yes.

>> If yes, then does it mean that spring implements JTS ??
Yes, as I said before you can configure Spring to use its JTS  which is  JtaTransactionManager.
0
 

Author Comment

by:letsbedecent
ID: 13854380
coool.,

Now, is it that spring over hibernate can replace the use of  servers like weblogic ?? (Unless ofcourse we need other services like Messaging )
0
 

Author Comment

by:letsbedecent
ID: 13854391
>> You do that when you define an XA datasource and you do that in your code programatically

Can you just briefly give me an idea of whats an XA Datasource.  


ejb-xml configuration we do define how our beans are involved in transaction,  how can we do that when using spring ?? i mean where do we tell these things like requires-new, supports, not-supported etc.,    
0
 
LVL 15

Accepted Solution

by:
aozarov earned 2000 total points
ID: 13854992
>> Can you just briefly give me an idea of whats an XA Datasource
An XA data source is a datasource that creats javax.sql.XAConection (as oposed to regular java.sql.Connection)
only those connections can participate in a JTA transaction and be part of 2PC.
see. http://java.sun.com/j2se/1.4.2/docs/api/javax/sql/XADataSource.html
and http://www.theserverside.com/discussions/thread.tss?thread_id=21385 for more info.

>> Now, is it that spring over hibernate can replace the use of  servers like weblogic ??
This is what the authors of spring claim, though you mentined rightly there are still services in the J2EE world
which don't exists as part of the spring framework (e.g JMS and MDB, JavaMail, Timer services, JCA, ...).

>> i mean where do we tell these things like requires-new, supports, not-supported etc.,    
That can be done both declaratively in the beans.xml or programatically (like in the ejb world)
see http://www.springframework.org/docs/reference/transaction.html#d0e4594
and http://www.springframework.org/docs/reference/transaction.html#d0e4693
for descripion about the two ways.
0
 

Author Comment

by:letsbedecent
ID: 13855180
One last question,

     do you ever sleep ??  :o)  

     r u an architect ??

0
 
LVL 15

Expert Comment

by:aozarov
ID: 13855205
>> do you ever sleep ??  :o)  
Yes, 4 hours per night ;-)

>> r u an architect ??
Not in my current position, a principal engineer.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question