• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

spring @Transactional

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, finally I found an article that clears things up a bit:
http://www.ibm.com/developerworks/java/library/j-ts1.html
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic