class MyService {
public void a() {
synchronized(somekey) {
b();
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void b() {
...do DB works...
}
}
My aim is
- 1 - get the key
- 2 - start transaction
- 3 - commit transaction
- 4 - release the key
When i call a() method from outside, transaction doesn't work.
Any suggestions ?
Thanks.
Unless you’re using code weaving, this can’t work.
The default way Spring handles transactions is through AOP proxies. The call to a transactional method goes like this:
If you call another method on the same object, you’re not going through the proxy, so there is no transactional behaviour.
If you don’t want to use AspectJ, you can get the proxy object using
AopContext.currentProxy().