File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Application Frameworks and the fly likes Transcation management at DO level using spring jdbc framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Transcation management at DO level using spring jdbc framework" Watch "Transcation management at DO level using spring jdbc framework" New topic
Author

Transcation management at DO level using spring jdbc framework

Ashok Sharma
Greenhorn

Joined: Dec 08, 2008
Posts: 12
we are using spring jdbc framework in our project.

Right now we have kept the transcation boundry at the service level which the entry point from client side to sever side.
We have applicationContext.xml file where we have defined the transcation boundry condition for each service.

here is piece of code of applicationContext.xml
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- the transactional semantics... -->
<tx:attributes>
<!--
all methods starting with 'select' or 'get' are read-only
all methods that start with save require a new transaction
-->
<tx:method name="select*" read-only="true" />
<tx:method name="get*" read-only="true"/>
<tx:method name="save*" propagation="REQUIRES_NEW" />
<tx:method name="insert*" read-only="false" propagation="REQUIRES_NEW" />
<tx:method name="update*" propagation="REQUIRES_NEW" />
<tx:method name="import*" propagation="REQUIRES_NEW" />
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>

<!-- @1. Ensure that the above transactional advice runs for any execution
of an operation defined by the service interfaces.
@2. Defines Transaction Manager Boundaries.
-->
<aop:config>
<aop:pointcut id="usersServiceOperation" expression="execution(* com.smartLMS.server.user.services.UserService.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="usersServiceOperation" />
</aop:config>

But in one case the entry point is one sevlet from where we call the sevice method and and from service we call a method from domain object
In this case the transcation boundry is not getting applied.
and if i want to set the transaction boundry in DO level how can i do this?

Please help.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

How is the Servlet getting the reference to the service. It must go through the Application Context in order to go through the proxy that sets up transactions. If the Servlet gets the service directly, it won't have a proxy and no transactions.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Roopali Gaikwad
Greenhorn

Joined: Mar 05, 2009
Posts: 4

The servlet is getting refernce to the service from application context only.
The logic of insert is like this
public String saveData()
{
for()
{
try{
insert1();
insert2();
insert3();
}catch(Exception e)
{
// RollBack here
}
}
}

If there is exception in 2nd insert it should roll back the Insert1() also but continue the loop. This logic is present in DO so i need to set the transation boundry condition at DO level.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Please post your xxx-servlet.xml configuration and your applicationContext.xml

And please use the CODE tags to make sure they keep their indentation for readability.

Thanks

Mark
prashant shelke
Greenhorn

Joined: Mar 10, 2009
Posts: 14
Hi I am also facing same issue as mentioned by Roopali,

for loop(n)
{
for loop_1()
{
Insert A()
Insert B()
Insert C()
}

for loop_2()
{
Insert D()
Insert E() --> throws RunTimeException
}
}
In above scenario records inserted by Loop 1 should be rolled back. Which is not working.
Flow of code is like

TestService.java(where transaction boundaries maintained) --> DO --> DAOImpl

TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

Note: I am using spring.jar version 2.0.1
prashant shelke
Greenhorn

Joined: Mar 10, 2009
Posts: 14
Please see detail post here:

Issue for spring rollback
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Transcation management at DO level using spring jdbc framework