开发者

@Transactional rollbackFor question

开发者 https://www.devze.com 2023-02-19 20:11 出处:网络
Supposing I mark a method @Transactional(rollbackFor = PersistenceException.class) in my Service layer and have a catch block as follows within开发者_运维问答 the method.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消