Say I have a `createdAt` field in my `@Entity`. a...
# spring
p
Say I have a
createdAt
field in my
@Entity
. and it gets its value as the Entity is created. Can this info be utilized, so that "all saved entity has non-null createdAt" at kotlin level, or do I have to check against null every time? Or I have no choice but declare it as
Copy code
var timestamp: Instant? = null,
d
I use like this var createdAt: Instant = Instant.now() protected set
s
No need for var, simple val createdAt: Instant = Instant.now() also works Default value is set when you create the entity before passing for repo save
👍 1
Update you use copy and override updatedAt - if you have that field. Assuming you’re using data class of course
p
Of course no data class.
Sometimes I need to provide the timestamp manually.