is there a way to force a transactional rollback without encountering an exception?

后端 未结 8 1942
鱼传尺愫
鱼传尺愫 2020-12-13 00:34

I have a method that does a bunch of things; amongst them doing a number of inserts and updates. It\'s declared thusly...

@Transactional(propagation = Propag         


        
相关标签:
8条回答
  • 2020-12-13 00:45

    This works for me:

    TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
    
    0 讨论(0)
  • 2020-12-13 00:50

    I have service methods annotated with @Transactional. When the validation fails, and I already have an entity attached to the current unit of work, I use sessionFactory.getCurrentSession().evict(entity) to make sure nothing is written to the database. That way I don't need to throw an exception.

    0 讨论(0)
提交回复
热议问题