https://kotlinlang.org logo
#exposed
Title
# exposed
n

Norg

07/23/2018, 2:33 PM
Hi everyone! Can anyone answer, is there nested transactions support?
t

tapac

07/23/2018, 2:53 PM
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

oshai

07/23/2018, 3:15 PM
@tapac it will help to add to the FAQ link mention of nested transactions.
n

Norg

07/23/2018, 4:42 PM
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

tapac

07/23/2018, 5:25 PM
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

Norg

07/25/2018, 7:45 AM
@tapac thank you very much!
6 Views