s1m0nw1
08/10/2018, 5:56 AMEntity
should be defined. It seems a good idea to just use data
classes. That's probably not the best thing to do though as properties (esp. auto-generated ID) change after an entity has been persisted, which makes the Kotlin-generated equals/hashcode functions yield other results (this is a problem in hashed collections e.g.). Read here: https://stackoverflow.com/questions/1638723/how-should-equals-and-hashcode-be-implemented-when-using-jpa-and-hibernateAlexjok
11/13/2018, 9:22 AMmariofelesdossantosjr
01/24/2019, 12:19 PMStian N
04/05/2020, 6:25 PMDavid Kubecka
01/17/2023, 12:54 PMBaseEntity
(from which all other non-embeddable entities in my model inherit):
@Id
@GeneratedValue
var id: Long? = null
A framework I'm currently integrating would benefit from having the annotations on the getters instead of fields so I did this:
@get:Id
@get:GeneratedValue
var id: Long? = null
Once I do that (and only that) I run into really weird Hibernate errors on the app startup, e.g. Could not locate setter method for property [com.vacuumlabs.robo.backend.entities.Money#amount]
. Well, Money#amount
is indeed just a val
but how is that related to moving the @Id
annotation to the getter? Moreover, Money
is exactly an embeddable entity that does not inherit from BaseEntity
...
Okay, so I switch it to var
and I get another error (from complete different entity): Unable to create unique key constraint (client_id, iban) on table account: database column 'client_id' not found
. But of course the client_id
column is there and if I switch the @Id
back to the property annotation then my app starts and runs ok.
I'm afraid I might be running into some generic issue here. Did anyone else encounter this?Youssef Habri
11/03/2023, 7:42 AMMultiTenantConnectionProvider
interface.
The issue I'm having is with isUnwrappableAs
and unwrap
functions:
class TenantSchemaConnectionProvider : MultiTenantConnectionProvider {
override fun isUnwrappableAs(unwrapType: Class): Boolean {
TODO("Not yet implemented")
}
override fun <T : Any?> unwrap(unwrapType: Class): T {
TODO("Not yet implemented")
}
// the rest of the overrides
}
In this case, the compiler complains with the following error: One type argument expected for class Class<T : Any!>
.
I've tried changing the types to Class<*>
and Class<T>
respectively, but that just makes the compiler complain the the functions are not overriding anything, and that the class has missing overrides from the interface.
Any idea how to solve this issue?Youssef Habri
11/03/2023, 7:52 AMclass TenantSchemaConnectionProvider : MultiTenantConnectionProvider {
override fun isUnwrappableAs(@NotNull unwrapType: Class<*>): Boolean {
return false
}
override fun <T> unwrap(@NotNull unwrapType: Class<T>): T? {
return null
}
// ...
}
But, the IDE still complains that it's wrong.
The compiler accepts it tho 🤔Youssef Habri
11/03/2023, 7:54 AM