File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes AOP sping Transaction in service layer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "AOP sping Transaction in service layer" Watch "AOP sping Transaction in service layer" New topic
Forums: Spring Aspect Oriented Programming
Author

AOP sping Transaction in service layer

Madhava Reddy Solipuram
Greenhorn

Joined: May 24, 2011
Posts: 11
Hi all,

I am trying to use spring AOP for transaction support in service layer, but it's not working please provide me the solution.

In my application i am using spring and hibernate.
following steps i have done to implement the transaction if i have missed any thing please guide me.

class PersonServiceProvider{
public void createPerson(...){
.....
calling the persistence layer for storing
eg personPersistence.save(..);
addressPersistence.save();
}
}

in each persistence layer am using the hibernate transaction for saving the data.
and xml configuration is
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="createPerson*" rollback-for="Throwable" propagation="NESTED"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aopointcut id="fooServiceOperation" expression="execution(* com.user.service.PersonServiceProvider.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/>
</aop:config>

when an exception is raised in middle of PersonServiceProvider createPerson() method it's not rollbacking the data.
what should i need to rollback the data if an exception is raised.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 973
    
    5

I think you need
Madhava Reddy Solipuram
Greenhorn

Joined: May 24, 2011
Posts: 11
James Boswell wrote:I think you need


Thanks for your quick replay.
I tried that also but no change when an exception is raised data is not rollbacking.
Madhava Reddy Solipuram
Greenhorn

Joined: May 24, 2011
Posts: 11
Hi all,

I tried AOP transaction in stand alone application its working, but its not working in web application.
Can any one suggest me i followed same approach for both the ways.
Madhava Reddy Solipuram
Greenhorn

Joined: May 24, 2011
Posts: 11
The problem is handling the exceptions in service layer. After removing try catch transaction worked normally
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AOP sping Transaction in service layer
 
Similar Threads
Spring Transaction using AOP in EJB Project
Transaction demarcation works with TransactionProxy but not AOP
Spring AOP, How does this example do it?
Spring, Hibernate, transaction Management | Cannot unwrap to requested type
transaction rollbacks, but a record is inserted?