acoconut
08/30/2021, 12:47 PMdata class Book (
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null
)
is way easier to read than:
data class Book (
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null
)
What do you all use if anything?Richard Gomez
08/30/2021, 1:47 PMveluxer
08/30/2021, 2:14 PMentity class
is not suitable for data class
. using class
is better than data class
because entity class
use mutable property. data class
use immutable property.
also, not nullable ID
is better then nullable ID
so, I would write code like below.
data class Book (
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0
)
If you use JPA, id will generate value automatically.Richard Gomez
08/30/2021, 2:21 PM@veluxer: There's nothing stopping you from usinguse immutable property.data class
var
instead, right?veluxer
08/30/2021, 2:29 PMMichael Böiers
08/30/2021, 8:42 PMacoconut
08/31/2021, 5:52 AMColton Idle
08/31/2021, 4:59 PM