Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insertIgnore() with get id fails for MySQL #574

Closed
StefanLiebig opened this issue Jun 5, 2019 · 2 comments
Closed

insertIgnore() with get id fails for MySQL #574

StefanLiebig opened this issue Jun 5, 2019 · 2 comments

Comments

@StefanLiebig
Copy link

If an already existing entry is inserted with insertIgnore() I get the error:

java.lang.IllegalStateException: users.id is not in record set
 	at org.jetbrains.exposed.sql.ResultRow.getRaw(Query.kt:59)
 	at org.jetbrains.exposed.sql.ResultRow.get(Query.kt:24)
 	at org.jetbrains.exposed.sql.statements.InsertStatement.get(InsertStatement.kt:24)
 	at timebox.users.UsersTableKt.insertUserIgnore(UsersTable.kt:149)
 	at timebox.users.UsersTableTest$test insert ignore user from existing user$1.invoke(UsersTableTest.kt:74)
 	at timebox.users.UsersTableTest$test insert ignore user from existing user$1.invoke(UsersTableTest.kt:9)
 	at timebox.test.MysqlTestTrait$transaction$1.invoke(MysqlTestTrait.kt:74)
 	at timebox.test.MysqlTestTrait$transaction$1.invoke(MysqlTestTrait.kt:28)
 	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:104)
 	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:75)
 	at timebox.test.MysqlTestTrait$DefaultImpls.transaction(MysqlTestTrait.kt:73)
 	at timebox.users.UsersTableTest.transaction(UsersTableTest.kt:9)
 	at timebox.users.UsersTableTest.test insert ignore user from existing user(UsersTableTest.kt:73)

The table definition is:

object Users : Table() {
    val id = intId()
    val initial = varchar("initial", INITIAL_LENGTH).uniqueIndex()
    val firstName = varchar("firstName", FIRST_NAME_LENGTH)
    val lastName = varchar("lastName", LAST_NAME_LENGTH)
    val serviceProvider = varchar("serviceProvider", SERVICE_PROVIDER_LENGTH)
    val adRef = varchar("adRef", AD_REF_LENGTH).uniqueIndex()
    val archived = bool("archived")
}

fun Table.intId(name: String = "ID") = this.integer(name).primaryKey().autoIncrement()

The insertIgnore() is:

        Users
                .insertIgnore {
                    if (user.id != null)
                        it[id] = user.id
                    it[initial] = user.initial
                    it[firstName] = user.firstName
                    it[lastName] = user.lastName
                    it[serviceProvider] = user.serviceProvider
                    it[adRef] = user.adRef
                    it[archived] = false
                } get Users.id

The jdbc driver is mysql-connector-java:8.0.12.

@Tapac Tapac changed the title insertIgnore() fails for MySQL insertIgnore() with get id fails for MySQL Jun 5, 2019
@Tapac Tapac closed this as completed Jun 5, 2019
@FabioGimmillaro
Copy link

@Tapac
I have a similar issue in an older version (0.17.3)

Stacktrace:
java.lang.IllegalStateException: kotlin.Unit is not in record set at org.jetbrains.exposed.sql.ResultRow.getRaw(Query.kt:59) at org.jetbrains.exposed.sql.ResultRow.get(Query.kt:24) at org.jetbrains.exposed.sql.statements.InsertStatement.get(InsertStatement.kt:21)

The statement:
MonthsSubmitted .insertIgnore { it[month] = month // ... } get MonthsSubmitted.id

This happens when two parallel transactions try to insert the same data into the MonthsSubmitted-table.

I'm using mysql-connector-java:8.0.17

@Tapac
Copy link
Contributor

Tapac commented Oct 12, 2019

@FabioGimmillaro , mysql driver doesn't return values with insert was ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants