Does anyone successfully use Hibernate with Kotlin...
# hibernate
s
Does anyone successfully use Hibernate with Kotlin? I'm currently looking for best practices as to how an
Entity
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-hibernate
m
I don't recommend to use data classes for Entity. I generate equals with help of IDE and hashcode by myself (return 13). Look at the following article for more information: https://thoughts-on-java.org/ultimate-guide-to-implementing-equals-and-hashcode-with-hibernate/ An entity has to have a default constructor and be open which you could fix with help of "kotlin-noarg" and kotlin-allopen" plugin: https://kotlinlang.org/docs/reference/compiler-plugins.html