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

Table with composite key created only with specific prop order #343

Closed
brezinajn opened this issue Jul 19, 2018 · 1 comment
Closed

Table with composite key created only with specific prop order #343

brezinajn opened this issue Jul 19, 2018 · 1 comment
Assignees
Labels

Comments

@brezinajn
Copy link

brezinajn commented Jul 19, 2018

object Foo: IdTable<Long>(){
    val bar = integer("bar").primaryKey()
    override val id: Column<EntityID<Long>> = long("id").entityId().autoIncrement().primaryKey()
}

This table produces crash on creation
org.jetbrains.exposed.exceptions.ExposedSQLException: java.sql.SQLSyntaxErrorException: Incorrect table definition; there can be only one auto column and it must be defined as a key

Simple solution is to switch the order of props:

object Foo: IdTable<Long>(){
    override val id: Column<EntityID<Long>> = long("id").entityId().autoIncrement().primaryKey()
    val bar = integer("bar").primaryKey()
}

Now the table creation goes smoothly.
Although there are situations where this workaround is not applicable (e.g. defining bar in abstract class and id in its child)

@Tapac Tapac self-assigned this Jul 20, 2018
@Tapac Tapac added the bug label Jul 20, 2018
@Tapac
Copy link
Contributor

Tapac commented Jul 20, 2018

Looks like a bug. As a workaround you can add index explicitly to primaryKey():

object Foo: IdTable<Long>(){
    val bar = integer("bar").primaryKey(2)
    override val id: Column<EntityID<Long>> = long("id").entityId().autoIncrement().primaryKey(1)
}

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

No branches or pull requests

2 participants