Hi everyone! Can anyone answer, is there nested tr...
# exposed
n
Hi everyone! Can anyone answer, is there nested transactions support?
t
No, because only a limited amount of the databases support nested transactions. You can use savepoints instead https://github.com/JetBrains/Exposed/wiki/FAQ#q-how-can-i-use-savepoint
o
@tapac it will help to add to the FAQ link mention of nested transactions.
n
according to this https://github.com/JetBrains/Exposed/wiki/DAO#many-to-many-reference I have to add references after creation transaction finished. Will savepoints help me? I need to be able to rollback the outer transaction along with creation if references were not added.
t
In that case you don't need to create separate transaction, just move
film.actors = SizedCollection(listOf(actor))
from
new
block.
Copy code
transaction {
	val actor = Actor.new {
		firstname = "Daisy"
		lastname = "Ridley"
    }
	val film = StarWarsFilm.new {
		name = "The Last Jedi"
		sequelId = 8
		director = "Rian Johnson"
    }
	film.actors = SizedCollection(listOf(actor))
}
Then on any exception within transaction block whole transaction will be rolled back
n
@tapac thank you very much!