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.zipAll 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