-
Notifications
You must be signed in to change notification settings - Fork 697
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.id is not in record set #1341
Comments
2021-09-11.20-17-15.mp4Behaviour current solution tables look fine column registration order affecting inserts. |
Oh, it was a very tricky bug! Thank you so much that you find out that columns order is matter (btw it fails only on SQLite and MySQL). I was able to fix it in the master and will release the fix on the week. A few things to make your code a bit less verbose - use predefined classes for IntTables and Entities (also public is a default visibility scope in Kotlin and can ba omitted): class Names(id: EntityID<Int>) : IntEntity(id) {
var first: String by NamesTable.first
var second: String by NamesTable.second
operator fun invoke(): Name = transaction {
Name(
id = this@Names.id.value,
first = first,
second = second
)
}
companion object : IntEntityClass<Names>(NamesTable) {
fun new(name: Name): Names = transaction {
new {
first = name.first
second = name.second
}
}
}
}
class Accounts( id: EntityID<Int>) : IntEntity(id) {
var name: Names by Names referencedOn AccountsTable.name
companion object : IntEntityClass<Accounts>(AccountsTable) {
public fun new(account: Account): Accounts = transaction {
new {
name = Names.new(account.name)
}
}
}
}
object NamesTable : IntIdTable("names_table") {
val first: Column<String> = varchar("first",50)
val second: Column<String> = varchar("second",50)
}
object AccountsTable : IntIdTable("accounts_table") {
val name: Column<EntityID<Int>> = reference("name", NamesTable)
} |
Thanks a lot. Working on a Dao and Table annotations processing thus the strict code requirements from Kotlin poet (public) :) Using the Entity to just have a unified code generation for the first phase will definitely consider using the generated ones once the code base is a bit more stable. |
You can also check https://github.com/JetBrains/exposed-intellij-plugin/tree/master/exposed-gradle-plugin as a code generator. |
I created rebo to avoid having to write some of the boilerplate code. Would appreciate any review. |
What does this error mean exactly?
exposed version 0.34.1
Data Classes
DAO Class
Table Class
On creating a new account I get
exposed version 0.34.1
mysql-jdbc connector
Not sure yet where I'm going wrong or if it's a bug.
Inserting a Name works fine
But inserting an Account throws
AccountsTable.id is not in record set
The text was updated successfully, but these errors were encountered: