You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
}
funmain(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.
The text was updated successfully, but these errors were encountered:
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:
This will generate the following output:
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.
The text was updated successfully, but these errors were encountered: