You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: Here we don’t use data classes with val properties because JPA is not designed to work with immutable classes or the methods generated automatically by data classes.
I use data class with val attributes with JPA annotations and JpaRepository and it seems to work (since a while).
DB: postgres 11
Spring: 2.3.4
Kotlin: 1.5.10
Java: 11
Q: Could You give more details to Your note?
Q2: Which pitfalls/limitations exist with immutable data classes?
Q3: This blog post address the same question. At the end with another conclusion. Who is wrong?
The text was updated successfully, but these errors were encountered:
To combat this issue, always override equals() and hashCode() when using data classes for entities.
This is absolutely safe to use. However, it almost defeats the purpose of using data classes, as it makes decomposition useless and only uses one field in toString(). A plain old class might be a better option for entities.
So it is possible to use data classes with a lot of care but JPA is not really designed to work with them, hence the choice to use regular mutable classes in this project.
I found Your note here ...
I use
data class
withval
attributes with JPA annotations andJpaRepository
and it seems to work (since a while).Q: Could You give more details to Your note?
Q2: Which pitfalls/limitations exist with immutable data classes?
Q3: This blog post address the same question. At the end with another conclusion. Who is wrong?
The text was updated successfully, but these errors were encountered: