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

Exposed executing things more than once when adding a DROP #112

Closed
Arcnor opened this issue May 24, 2017 · 1 comment
Closed

Exposed executing things more than once when adding a DROP #112

Arcnor opened this issue May 24, 2017 · 1 comment

Comments

@Arcnor
Copy link

Arcnor commented May 24, 2017

For the following SSCCE:

package com.arcnor.test.exposed

import org.jetbrains.exposed.dao.*
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction

object Things : IntIdTable() {
	val name = varchar("name", 42)
}

class Thing(id: EntityID<Int>) : IntEntity(id) {
	companion object : IntEntityClass<Thing>(Things)

	var name by Things.name
}

fun main(args: Array<String>) {
	Database.connect("jdbc:postgresql://localhost:5432/test", driver = "org.postgresql.Driver", user = "postgres")

	transaction {
		SchemaUtils.create(Things)

		println(Thing.new { name = "test" })

		SchemaUtils.drop(Things)
	}
}

The following output and error will be thrown, as if Exposed was trying to execute things more than once. If you remove the DROP, everything works fine:

09:47:10.690 [main] DEBUG Exposed - CREATE TABLE IF NOT EXISTS things (id SERIAL PRIMARY KEY, name VARCHAR(42) NOT NULL)
com.arcnor.test.exposed.Thing@700fb871
09:47:10.706 [main] DEBUG Exposed - DROP TABLE things
09:47:10.718 [main] INFO Exposed - Transaction attempt #0: Batch entry 0 INSERT INTO things (name) VALUES ('test')
RETURNING "id" was aborted: ERROR: relation "things" does not exist
  Position: 13  Call getNextException to see other errors in the batch.. Statement: INSERT INTO things (name) VALUES ('test')
RETURNING "id"
java.sql.BatchUpdateException: Batch entry 0 INSERT INTO things (name) VALUES ('test')
RETURNING "id" was aborted: ERROR: relation "things" does not exist
  Position: 13  Call getNextException to see other errors in the batch.
	at org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:148)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2190)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:472)
	at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:791)
	at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1547)
	at org.jetbrains.exposed.sql.statements.InsertStatement.executeInternal(InsertStatement.kt:50)
	at org.jetbrains.exposed.sql.statements.InsertStatement.executeInternal(InsertStatement.kt:10)
	at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_main(Statement.kt:57)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:108)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:102)
	at org.jetbrains.exposed.sql.statements.Statement.execute(Statement.kt:28)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert(Queries.kt:44)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert$default(Queries.kt:37)
	at org.jetbrains.exposed.dao.EntityCache.flushInserts$exposed_main(Entity.kt:403)
	at org.jetbrains.exposed.dao.EntityCache.flush(Entity.kt:357)
	at org.jetbrains.exposed.dao.EntityCache.flush(Entity.kt:349)
	at org.jetbrains.exposed.sql.Transaction.flushCache(Transaction.kt:72)
	at org.jetbrains.exposed.sql.Transaction.commit(Transaction.kt:61)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:71)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:58)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:49)
	at com.arcnor.test.exposed.ExposedIssueKt.main(ExposedIssue.kt:75)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "things" does not exist
  Position: 13
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189)
	... 20 common frames omitted
com.arcnor.test.exposed.Thing@769a1df5
09:47:10.734 [main] DEBUG Exposed - DROP TABLE things
09:47:10.736 [main] INFO Exposed - Transaction attempt #1: Batch entry 0 INSERT INTO things (name) VALUES ('test')
RETURNING "id" was aborted: ERROR: relation "things" does not exist
  Position: 13  Call getNextException to see other errors in the batch.. Statement: INSERT INTO things (name) VALUES ('test')
RETURNING "id"
java.sql.BatchUpdateException: Batch entry 0 INSERT INTO things (name) VALUES ('test')
RETURNING "id" was aborted: ERROR: relation "things" does not exist
  Position: 13  Call getNextException to see other errors in the batch.
	at org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:148)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2190)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:472)
	at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:791)
	at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1547)
	at org.jetbrains.exposed.sql.statements.InsertStatement.executeInternal(InsertStatement.kt:50)
	at org.jetbrains.exposed.sql.statements.InsertStatement.executeInternal(InsertStatement.kt:10)
	at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_main(Statement.kt:57)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:108)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:102)
	at org.jetbrains.exposed.sql.statements.Statement.execute(Statement.kt:28)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert(Queries.kt:44)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert$default(Queries.kt:37)
	at org.jetbrains.exposed.dao.EntityCache.flushInserts$exposed_main(Entity.kt:403)
	at org.jetbrains.exposed.dao.EntityCache.flush(Entity.kt:357)
	at org.jetbrains.exposed.dao.EntityCache.flush(Entity.kt:349)
	at org.jetbrains.exposed.sql.Transaction.flushCache(Transaction.kt:72)
	at org.jetbrains.exposed.sql.Transaction.commit(Transaction.kt:61)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:71)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:58)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:49)
	at com.arcnor.test.exposed.ExposedIssueKt.main(ExposedIssue.kt:75)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "things" does not exist
  Position: 13
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189)
	... 20 common frames omitted
com.arcnor.test.exposed.Thing@2438dcd
09:47:10.751 [main] DEBUG Exposed - DROP TABLE things
09:47:10.752 [main] INFO Exposed - Transaction attempt #2: Batch entry 0 INSERT INTO things (name) VALUES ('test')
RETURNING "id" was aborted: ERROR: relation "things" does not exist
  Position: 13  Call getNextException to see other errors in the batch.. Statement: INSERT INTO things (name) VALUES ('test')
RETURNING "id"
java.sql.BatchUpdateException: Batch entry 0 INSERT INTO things (name) VALUES ('test')
RETURNING "id" was aborted: ERROR: relation "things" does not exist
  Position: 13  Call getNextException to see other errors in the batch.
	at org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:148)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2190)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:472)
	at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:791)
	at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1547)
	at org.jetbrains.exposed.sql.statements.InsertStatement.executeInternal(InsertStatement.kt:50)
	at org.jetbrains.exposed.sql.statements.InsertStatement.executeInternal(InsertStatement.kt:10)
	at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_main(Statement.kt:57)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:108)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:102)
	at org.jetbrains.exposed.sql.statements.Statement.execute(Statement.kt:28)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert(Queries.kt:44)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert$default(Queries.kt:37)
	at org.jetbrains.exposed.dao.EntityCache.flushInserts$exposed_main(Entity.kt:403)
	at org.jetbrains.exposed.dao.EntityCache.flush(Entity.kt:357)
	at org.jetbrains.exposed.dao.EntityCache.flush(Entity.kt:349)
	at org.jetbrains.exposed.sql.Transaction.flushCache(Transaction.kt:72)
	at org.jetbrains.exposed.sql.Transaction.commit(Transaction.kt:61)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:71)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:58)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:49)
	at com.arcnor.test.exposed.ExposedIssueKt.main(ExposedIssue.kt:75)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "things" does not exist
  Position: 13
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189)
	... 20 common frames omitted
Exception in thread "main" java.sql.BatchUpdateException: Batch entry 0 INSERT INTO things (name) VALUES ('test')
RETURNING "id" was aborted: ERROR: relation "things" does not exist
  Position: 13  Call getNextException to see other errors in the batch.
	at org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:148)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2190)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:472)
	at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:791)
	at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1547)
	at org.jetbrains.exposed.sql.statements.InsertStatement.executeInternal(InsertStatement.kt:50)
	at org.jetbrains.exposed.sql.statements.InsertStatement.executeInternal(InsertStatement.kt:10)
	at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_main(Statement.kt:57)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:108)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:102)
	at org.jetbrains.exposed.sql.statements.Statement.execute(Statement.kt:28)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert(Queries.kt:44)
	at org.jetbrains.exposed.sql.QueriesKt.batchInsert$default(Queries.kt:37)
	at org.jetbrains.exposed.dao.EntityCache.flushInserts$exposed_main(Entity.kt:403)
	at org.jetbrains.exposed.dao.EntityCache.flush(Entity.kt:357)
	at org.jetbrains.exposed.dao.EntityCache.flush(Entity.kt:349)
	at org.jetbrains.exposed.sql.Transaction.flushCache(Transaction.kt:72)
	at org.jetbrains.exposed.sql.Transaction.commit(Transaction.kt:61)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:71)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:58)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:49)
	at com.arcnor.test.exposed.ExposedIssueKt.main(ExposedIssue.kt:75)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "things" does not exist
  Position: 13
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189)
	... 20 more
@YakovSirotkin
Copy link
Contributor

The problem here caused by table deletion before transaction commit.

    transaction {
        SchemaUtils.create(Things)
        println(Thing.new { name = "test" })
    }
    transaction {
        SchemaUtils.drop(Things)
    }

works fine.

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