posted 13 years ago
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