Bassirou Rabo
Bassirou Rabo

Reputation: 21

postgresql Transaction isolation level 4 not supported

I am Trying to create table (postgres + exposed + ktor + JDBC), I got that error.

Find bellow the configuration I have:

build.gradle

compile group: 'postgresql', name: 'postgresql', version: '9.0-801.jdbc4'

Hello.kt

object Pays : Table() {
val id = integer("id").autoIncrement().primaryKey() // Column
val name = varchar("name", 50) // Column
}

fun main(args: Array) {
Database.connect("jdbc:postgresql://localhost/my_db", driver = "org.postgresql.Driver", user = "user", password = "password")

HERE IS THE ERROR I GOT

Caused by: org.postgresql.util.PSQLException: Transaction isolation level 4 not supported.
at org.postgresql.jdbc2.AbstractJdbc2Connection.setTransactionIsolation(AbstractJdbc2Connection.java:826)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction$connectionLazy$1.invoke(ThreadLocalTransactionManager.kt:25)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction$connectionLazy$1.invoke(ThreadLocalTransactionManager.kt:20)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:154)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction.getConnection(ThreadLocalTransactionManager.kt:29)
at org.jetbrains.exposed.sql.Transaction.getConnection(Transaction.kt)
at org.jetbrains.exposed.sql.Database.getMetadata$exposed(Database.kt:17)
at org.jetbrains.exposed.sql.Database$url$2.invoke(Database.kt:26)
at org.jetbrains.exposed.sql.Database$url$2.invoke(Database.kt:15)
at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:131)
at org.jetbrains.exposed.sql.Database.getUrl(Database.kt)
at org.jetbrains.exposed.sql.Database$dialect$2.invoke(Database.kt:29)
at org.jetbrains.exposed.sql.Database$dialect$2.invoke(Database.kt:15)
at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:131)
at org.jetbrains.exposed.sql.Database.getDialect$exposed(Database.kt)
at org.jetbrains.exposed.sql.vendors.DefaultKt.getCurrentDialect(Default.kt:319)
at org.jetbrains.exposed.sql.vendors.DefaultKt.getCurrentDialectIfAvailable(Default.kt:323)
at org.jetbrains.exposed.sql.Column.getOnDelete$exposed(Column.kt:14)

Upvotes: 0

Views: 3189

Answers (2)

Rosmi
Rosmi

Reputation: 56

Please try updating build.gradle

compile group: 'org.postgresql', name: 'postgresql', version: '9.4-1200-jdbc41'

Upvotes: 0

Laurenz Albe
Laurenz Albe

Reputation: 246493

Reading the source of the JDBC driver version 9.0, I see:

/*
 * You can call this method to try to change the transaction
 * isolation level using one of the TRANSACTION_* values.
 *
 * <B>Note:</B> setTransactionIsolation cannot be called while
 * in the middle of a transaction
 *
 * @param level one of the TRANSACTION_* isolation values with
 * the exception of TRANSACTION_NONE; some databases may
 * not support other values
 * @exception SQLException if a database access error occurs
 * @see java.sql.DatabaseMetaData#supportsTransactionIsolationLevel
 */
public void setTransactionIsolation(int level) throws SQLException
{
    checkClosed();

    if (protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
        throw new PSQLException(GT.tr("Cannot change transaction isolation level in the middle of a transaction."),
                                PSQLState.ACTIVE_SQL_TRANSACTION);

    String isolationLevelName = getIsolationLevelName(level);
    if (isolationLevelName == null)
        throw new PSQLException(GT.tr("Transaction isolation level {0} not supported.", new Integer(level)), PSQLState.NOT_IMPLEMENTED);

    String isolationLevelSQL = "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL " + isolationLevelName;
    execSQLUpdate(isolationLevelSQL); // nb: no BEGIN triggered
}

getIsolationLevelName is defined like this:

protected String getIsolationLevelName(int level)
{
    boolean pg80 = haveMinimumServerVersion("8.0");

    if (level == Connection.TRANSACTION_READ_COMMITTED)
    {
        return "READ COMMITTED";
    }
    else if (level == Connection.TRANSACTION_SERIALIZABLE)
    {
        return "SERIALIZABLE";
    }
    else if (pg80 && level == Connection.TRANSACTION_READ_UNCOMMITTED)
    {
        return "READ UNCOMMITTED";
    }
    else if (pg80 && level == Connection.TRANSACTION_REPEATABLE_READ)
    {
        return "REPEATABLE READ";
    }

    return null;
}

Since java.sql.Connection.TRANSACTION_REPEATABLE_READ is 4, your error message can only mean that pg80 is false.

So the only explanations are that you are actually using a PostgreSQL server version older than 8.0 or, more likely, that you are using PostgreSQL v10 and the JDBC driver is too old to understand the new two-number version numbering system.

In the first case, you should upgrade PostgreSQL, but in any event, you should use a current version of the JDBC driver. That should take care of your problem.

Upvotes: 1

Related Questions