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

Using a sequence for auto-incremented IDs only works for certain dialects #492

Closed
timmhirsens opened this issue Feb 11, 2019 · 0 comments
Closed

Comments

@timmhirsens
Copy link

Using a sequence to generate IDs is the prefered way to do ID generation in ORMs like JPA/Hibernate.

Exposed also supports id generation based on sequences. However it only does so for SQL dialects that do not support native auto increment columns.

To make migration of existing database from JPA/Hibernate to Exposed more smoothly it would be great if a sequence could also be used for dialects capable of auto increment columns.

Assuming the following code:

object Cities : Table() {
    val id = integer("id").autoIncrement("my_sequence").primaryKey()
    var name = varchar("name", 255)
}

fun main(args: Array<String>) {
    Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver")
    transaction {
        SchemaUtils.create(Cities)
        println(Cities.id.autoIncSeqName)
    }
}

This will generate the following output:

07:19:05.969 [main] DEBUG Exposed - CREATE TABLE IF NOT EXISTS CITIES (ID INT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(255) NOT NULL)
null

The sequence name for the autoincrement column is ignored, because the used dialect (H2 in this case, same applies for postgresql and others) is capable of native Auto Increment fields.

IMHO: Explicitly declaring a sequence name here should always lead to a sequence beeing used.

@Tapac Tapac self-assigned this Feb 15, 2019
Tapac added a commit that referenced this issue Apr 19, 2021
…ects #492

Support sequences in SQL Server #1164
Sequence is not used when specifying via autoIncrement #1209
@Tapac Tapac closed this as completed Apr 20, 2021
SchweinchenFuntik pushed a commit to SchweinchenFuntik/Exposed that referenced this issue Oct 23, 2021
…ects JetBrains#492

Support sequences in SQL Server JetBrains#1164
Sequence is not used when specifying via autoIncrement JetBrains#1209
SchweinchenFuntik pushed a commit to SchweinchenFuntik/Exposed that referenced this issue Oct 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants