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

后端 未结 8 1980
鱼传尺愫
鱼传尺愫 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: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.

提交回复
热议问题