Skip to content

Postgres has auto commit on by default making commit / rollback not an option #21

Description

@janvladimirmostert
val dbConnection = PgConnection.create("jdbc:postgresql://localhost:5432/mydb")
val transaction = dbConnection.createTransaction()
update(TestEntity).set(
    TestEntity.name, "BLEH ${Random().nextInt()}"
).where(TestEntity.id eq 1).executeOn(transaction)
transaction.commit()

This causes a postgres error:

Cannot commit when autoCommit is enabled.

C3P0, Hikari and regular JDBC allows you to turn off autocommit on the connection itself.

Where would be a reasonable place to add such a property, on PgConnection and its parent classes themselves?

val dbConnection = PgConnection.create(
    "jdbc:postgresql://localhost:5432/mydb", 
    ConnectionOptions(autoCommit = false
))

The workaround for now is to switch off autocommit on the DB level which is not always an option when using a DB hosted by someone else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions