aspose file tools
The moose likes Spring and the fly likes spring @Transactional Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Spring
Reply Bookmark "spring @Transactional" Watch "spring @Transactional" New topic
Author

spring @Transactional

pete reisinger
Ranch Hand

Joined: Dec 30, 2009
Posts: 46
Hi,
I'm having difficulties to understand how @Transactional works.
This is how I understand it, please let me know if it is correct.

so method annotated by @Transactional annotation with value propagation.REQUIRES_NEW, REQUIRED etc. tells underlying db that the query(ies) shoud be transactional, so if there's any error then it should roll back changes made (if any)
readOnly=true marks that transaction is read only

the problem is if I call two transactional methods - getById(..) and delete(...), both of them are transactional (first is propagation.REQUIRED, readOnly=true, second propagation.REQUIRES_NEW, readOnly=false
then I get exception that i have two opened sessions.
If second is propagation.REQUIRED then I get exception saying that the object will be resaved. I suppose that it is because both use the same transaction (because it is in one request) and if first one marks it as read only then it cannot be overriden by second one, so it throws exception and is rolled back, therefore resaved.

so it is not really about methods annotated by @Transactional but also in which order they are called. because it applies on the whole request (I'm talking about mvc web application)

the way my service methods are now is: getters - propagation.NOT_SUPPORTED and save, delete propagation.REQUIRES_NEW
is it correct?

thanks
pete reisinger
Ranch Hand

Joined: Dec 30, 2009
Posts: 46
ok, finally I found an article that clears things up a bit:
http://www.ibm.com/developerworks/java/library/j-ts1.html
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: spring @Transactional
 
Similar Threads
Problem with @Transactional annotation
Spring Transactions with hibernate
Transaction support of Session Beans
Why should I use annotations and what are those?
Understand regarding REQUIRED and REQUIRES_NEW