Hi all. I'm looking into Kotlin + JPA, and most of...
# getting-started
b
Hi all. I'm looking into Kotlin + JPA, and most of the examples I've seen so far are using Kotlin Data classes. But while I (think I) understand data classes, I don't understand what the added benefit is in regards to JPA. Anyone suggestions?
m
Statement of obvious. Data classes basically add
toString
,
equals
and
hashCode
. If the JPA implementation leverages any of those functions (i.e. you were defining them when/if you worked in Java), then you don’t have to define them manually. If the JPA doesn’t rely on those, then strictly answering your question, it doesn’t add any value for JPA. Of course as soon as you use the model objects in your code, those functions may be beneficial.
t
apparently they are not even good with jpa: https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/ but honestly I am using them and don't really know how much of the consistency problem described is practical and how much is theoretical (still have to encounter the issue described since using data classes)
m
Hmm, so a case of people defaulting to ‘it looks like a POJO, so I should/must use data class’. Not currently using JPA so no first hand experience here, so thank you for the link as it will be something I’ll have to research if we do start using JPA.
b
Thanks for the replies, this sort of confirms what I thought. This was triggered because we have a byte array in our jpa class, and Intellij warns about that.