https://kotlinlang.org logo
#spring
Title
d

deviant

09/18/2019, 6:42 AM
data class is preferable (see data class benefits). and
middleName
should be nullable type
t

thanksforallthefish

09/18/2019, 6:49 AM
data class are not preferable, equals and hashcode are better off as db ids when thinking jpa
3
d

deviant

09/18/2019, 9:02 AM
i use data classes with hibernate for years. what exact problems do you mean?
k

kqr

09/18/2019, 10:19 AM
cant you override equals and hashcode in data class?
j

Jason Feng

09/18/2019, 11:04 AM
Hi guys, thanks for the reply, which lead me to google more deeper into this, and I found this statement from Spring Data
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. If you are using other Spring Data flavor, most of them are designed to support such constructs so you should use classes like data class User(val login: String, …​) when using Spring Data MongoDB, Spring Data JDBC, etc.
d

deviant

09/18/2019, 2:30 PM
i use models like this one a lot:
Copy code
data class Funnel(
    @ManyToOne
    @JoinColumn
    @JsonIgnore
    val product: CompanyProduct,
    var name: String,
    @Enumerated(EnumType.STRING)
    var state: State = State.ACTIVE,
    val createdAt: Instant = Instant.now(),
    var updatedAt: Instant = Instant.now(),
    var archivedAt: Instant? = null,
    @Id @GeneratedValue
    val id: Long = 0
)
have no any problems so far
l

Luis Munoz

09/19/2019, 3:41 PM
Same here but I am beginning to think that is because the problem is with hashing and equals which are used to knwo when to fetch an item from the db, which would be difficult to spot a problem
5 Views