@Transactional rollbackFor question
Supposing I mark a method @Transactional(rollbackFor = PersistenceException.class)
in my Service layer and have a catch block as follows within开发者_运维问答 the method.
try{
serverStore.update(persistableObject);
} catch (PersistenceException e) {
}
Will I ever even catch the PersistenceException?
I ask because the Persistence exception I'm guarding for is an intermittent deadlocking issue and I can't tell if I just haven't reproduced it since this change or it's not supposed to show up.
It depends on how you flush the session (entity manager). By default, I think, it will get flush when the transaction is committed, so you won't be able to catch the exception in the method.
精彩评论