Skip to content

Allow global default for @Transactional rollback behavior on checked exceptions #23473

Closed
@ilyastam

Description

@ilyastam

In Kotlin all exceptions are effectively unchecked. Therefore, transactions will not be rolled back for functions like this:

@Transactional
fun example(): Unit {
  runQuery()
  throw MyCheckedException()
  runQuery()
}

to achieve a correct behavior, the above code needs to be refactored as follows:

@Transactional(rollbackFor = [Exception::class])
fun example(): Unit {
  runQuery()
  throw MyCheckedException()
  runQuery()
}

this isn't very intuitive and can lead to unexpected results. Furthermore, even if a developer is aware of this, he/she should not forget to specify rollbackFor for every @Transactional annotation.

It should be possible to configure application-wide defaults for rollbackFor and noRollbackFor

Metadata

Metadata

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions