nicholasnet
06/11/2020, 7:20 PMid
property value of generic T
this is my code.
class BaseRepository(val client: DatabaseClient, val dataAccessStrategy: ReactiveDataAccessStrategy) {
suspend inline fun <reified T> save(entity: T): T {
val id = // How to get the id of entity?
try {
return client.insert()
.into(T::class.java)
.using(entity)
.map(dataAccessStrategy.converter.populateIdIfNecessary(entity))
.awaitOne()
} catch (exception: Exception) {
throw exception
}
}
}
What is the best approach to get the id of entity here?Brian Dilley
06/11/2020, 10:47 PMT : IdentifiableObject
where IdentifiableObject
has an ID property. But then all of your entities have to implement that interface.nicholasnet
06/11/2020, 11:48 PMMatteo Mirk
06/12/2020, 1:28 PME.Kisaragi
06/13/2020, 1:24 PM