I'm having a weird issue with Hibernate. Not sure ...
# hibernate
d
I'm having a weird issue with Hibernate. Not sure whether it's Kotlin specific but it seems to be quite generic so I guess Java guys would already complain 🙂 I have this in my
BaseEntity
(from which all other non-embeddable entities in my model inherit):
Copy code
@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:
Copy code
@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?
👍 1
d
We have the exact same issue after we upgraded to hibernate 6 with Spring Boot 3. Were you able to resolve it? It seems to be a specific issue when using inheritance…
d
I eventually learned it is caused by how the access strategy is defined in Hibernate: https://thorben-janssen.com/access-strategies-in-jpa-and-hibernate/. Quite a weird implicit stuff if you ask me 🙂