Closed pindab0ter closed 2 years ago
Seems like Exposed is not able to figure out the name of the table from your table class. Not sure why it only happens in 0.39, as this code wasn't changed in a year: https://github.com/JetBrains/Exposed/blob/2feb5505bb02ef75bf5ddb32395b5fa4c8c7f001/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt#L334
Can you please rename your Coop
to CoopTable
or try and specify the table explicitly?
@pindab0ter , can you share your Farmers
table declaration and what Java version do you use?
Seems like Exposed is not able to figure out the name of the table from your table class. Not sure why it only happens in 0.39, as this code wasn't changed in a year:
Can you please rename your
Coop
toCoopTable
or try and specify the table explicitly?
The table name was already explicitly defined:
object Coops : IntIdTable() {
override val tableName = "coops"
@pindab0ter , can you share your
Farmers
table declaration and what Java version do you use?
The project uses Java version 11 (Azul Zulu 11.0.16, specifically), defined through kotlinOptions.jvmTarget
and as the Project SDK in IntelliJ.
This is what Farmers.kt
looks like:
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.sql.ReferenceOption.CASCADE
import org.jetbrains.exposed.sql.jodatime.datetime
import org.joda.time.DateTime.now
object Farmers : IdTable<String>() {
override val tableName = "farmers"
override val id = text("id").entityId()
override val primaryKey = PrimaryKey(id)
val userId = reference("id", Users, CASCADE, CASCADE)
// text, integer, double and long fields
val createdAt = datetime("created_at").clientDefault { now() }
val updatedAt = datetime("updated_at").clientDefault { now() }
}
I would like to reiterate that version 0.38.2 doesn't have this problem.
The earlier mentioned Coop
and Farmer
DAOs do have many-to-many relations defined:
// Farmer.kt (DAO)
// ...
var coops by Coop via CoopFarmers
// ...
// Coop.kt (DAO)
// ...
var farmers by Farmer via CoopFarmers
// ...
// CoopFarmers.kt (DSL)
object CoopFarmers : Table() {
override val tableName = "coop_farmers"
val farmer = reference("farmer", Farmers, CASCADE, CASCADE)
val coop = reference("coop", Coops, CASCADE, CASCADE)
init {
index(true, farmer, coop)
}
}
I was able to reproduce the bug, will fix it with next release. As a workaround you can move table name into table declaration like:
object Farmers : IdTable<String>{"farmers") { ... }
object CoopFarmers : Table("coop_farmers") { ... }
It should help
Awesome! Glad to hear you were able to reproduce the problem.
Thank you for providing a workaround as well. I will give that a go.
Do you want to leave this issue open until there’s a commit/PR/release with a fix, or should I close it?
I'll close it just after all tests will pass on CI. The fix is on the way.
When updating from 0.38.2 to 0.39.1 or .2 my application breaks.
When I'm trying to load one or more instances of the
Farmer
DAO from theFarmers
DSL, this error occurs:The error message doesn't tell me what went wrong specifically. It's not clear to me, at least.
Even though I'm not loading or using this relationship (no eager loading or calling it), it seems to originate in the
Coops
DSL, with the relation defined like this:Unfortunately I can't open source the code. So please let me know what more details I should provide.
The error occurs even when the
coops
table is completely empty. No non-nullable fields in Farmer are null.With 3.8.2 this worked without a problem.