-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: solved JPA - Hibernate - TransactionPropagation.REQUIRES_NEW
PostPosted: Sun Feb 19, 2012 1:35 pm 
Newbie

Joined: Sun Feb 19, 2012 1:32 pm
Posts: 2
Hi,

I'm building an Java Web Application based on Spring (Web MVC) with a backend managed by JPA with Hibernate (using EntityManager). While developping, I use MySQL 5 Server (with InnoDB engine).

I'm experiencing troubles with the transactions.

I've a service method which imports a lot of data via web services. For each piece of data, a second method is called to do some operations in the database. The first method is annoted @Transactional(/* implicit required propagation */), the second is annoted with @Transactional(propagation = REQUIRES_NEW).

In fact, data have to be computed in order of arrival. If a treatment fails, data already present should remain, but all the changes made during a data computing have to be removed.

Code:
MyServiceImpl implements MyService {
     @Override   
     @Transactional
     public void getLastChanges() {
         List<Change> changes = ...

         for(Change change : changes) {
             insertChange(change);
         }
     }

     @Override
     @Transactional(propagation = REQUIRES_NEW)
     public void insertChange(Change change) {
         // insert a row in a table
         // update an other table
         // ...
         // after all, all is ok
     }   
}


With this example, if the service retrieves 5 changes, and the 3th change computing fails, the 2 firsts changes will be computed and saved in database. All updates made while computing the 3th change have to be cleared (rollback...).

The problem is that the rollback seem to not be done.

I wrote a little program that demonstrates this behavior. This program requires a MySQL 5 Server. It's available on http://www.rclsilver.net/temp/test-jpa.zip

All versions used in this application are the same as my final application.

Thanks in advance...

PS: I'v posted the same message on Spring forums: http://forum.springsource.org/showthrea ... esn-t-work


Last edited by rclsilver on Mon Feb 20, 2012 6:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: JPA - Hibernate - TransactionPropagation.REQUIRES_NEW
PostPosted: Mon Feb 20, 2012 6:18 am 
Newbie

Joined: Sun Feb 19, 2012 1:32 pm
Posts: 2
The problem has been solved with a answer on the spring forum. The AOP wasn't done because i called my sub-method as internal. I've exported the getLastChanges() method into an other bean and this works fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.