How to Rollback in JetBrains/Exposed?

I have started using Kotlin Exposed. One of the early difficulties I got into was that I can’t seem to be able to do a rollback. eg.

transaction {
val result = doSomething()
if (result == false) {

In the above code, doSomething() invokes many {… }. I want to commit or rollback based on the overall result. However all the DAOs automatically get inserted into the table and the transaction committed. If the question is not entirely clear I could easily contribute a test case.

PS: I tried this.connection.rollback() also.

Why not use transaction block in your DAOs ?

A real example in Spring Boot:

open fun sendMessage(sender: String, receiver: String, content: Map<String, Any>): Message? {
    return transaction {
        try {
            val message = Chat.slice(, Chat.createdAt, Chat.sender, Chat.receiver, Chat.content, Chat.readAt).select {
                    it[Chat.sender] = sender
                    it[Chat.receiver] = receiver
                    it[Chat.content] = js.writeValueAsString(content)
                }[]) and Chat.deletedAt.isNull()
            }.limit(1).map {
                Message(id = it[], createdAt = it[Chat.createdAt], sender = it[Chat.sender], receiver = it[Chat.receiver], content = it[Chat.content], readAt = it[Chat.readAt])

            message?.let { zsetOps.add(sender, receiver, }
        } catch (e: Exception) {
            throw e

Thanks for the replies. Finally manged through explicit control of transactions rather than using transaction blocks, since throwing in exception in order to trigger a rollback wasn’t quite appropriate in our context.

Please try TransactionManager.current().rollback(). You can call it anywhere inside transaction{} block to roll back all uncommited changes.

AFAIK, I had tried it (just like I had tried this.rollback()). But nevertheless go back and check once again.

I just tried it out. Yes, TransactionManager.current().rollback() worked and rolled back all uncommitted changes.