usr-local-ΕΨΗΕΛΩΝ
usr-local-ΕΨΗΕΛΩΝ

Reputation: 26904

Changing default rollbackFor behaviour for any Exception

By default, Spring's Transactional annoation won't rollback on checked exceptions.

One can use Transactional's rollbackFor attribute to override this.

Is it possible to override this behaviour globally rather than on each annotation?

I have methods that throw IOException. A possibility could be wrapping those exceptions in RuntimeException, as they are unrecoverable for my code.

Upvotes: 0

Views: 538

Answers (1)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 299068

There are two approaches that I am aware of:

  1. Create your own Meta-Annotation that handles your particular
    transaction semantics
  2. Write an aspect (either around or after-throwing) that wraps all checked exceptions in RuntimeExceptions

Upvotes: 3

Related Questions