yes, id is null before entity is persisted, but wh...
# announcements
c
yes, id is null before entity is persisted, but when retrieved from repository, that is impossible. So far I came up with this design:
Copy code
@Entity
class MyEntity {
	@Id
	private val _id: Long? = null
	@Transient
	val id: Long
		get () = checkNotNull(_id) { "Should not try to retrieve ID of an entity before it is persisted" }
}
p
I remember someone came up with idea to have an Entity with generic id and type aliases: - for new Entity: with
Nothing
type - for stored Entity: with
Long
type Something like this https://pl.kotl.in/r1ffD2k-V but I don’t remember the exact implementation.
c
Looks intriguing, I'll test the idea, thanks
👍 1