https://kotlinlang.org logo
Title
c

Czar

12/25/2018, 12:59 PM
yes, id is null before entity is persisted, but when retrieved from repository, that is impossible. So far I came up with this design:
@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

Pavlo Liapota

12/25/2018, 1:46 PM
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

Czar

12/25/2018, 2:17 PM
Looks intriguing, I'll test the idea, thanks
👍 1