You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the r2dbc mapping functionality to map joined entities via alias prefixes:
overridesuspendfunfindByIdJoined(id:Long): Fruit? {
return databaseClient.execute("select f.*, t.id as t_id, t.kind as t_kind from fruit f left join tree t on t.id = f.tree_id where f.id = :id")
.bind("id", id)
.map { row, rowMetaData ->val fruitEntity = converter.read(Fruit::class.java, row, rowMetaData)
val joinedTreeEntity = converter.read<Tree>(row, "t_")
fruitEntity.copy(joinedTree = joinedTreeEntity)
}.awaitFirstOrNull()
}
privateinlinefun <reifiedT> R2dbcConverter.read(row:Row, aliasPrefix:String): T= read(T::class.java,
object:Row {
overridefun <T:Any?> get(index:Int, type:Class<T>) = row[index, type]
overridefun <T:Any?> get(name:String, type:Class<T>) = row["$aliasPrefix$name", type]
}
)
I can easily map the root entity (tree) via read(type, row, rowMetadata). Mapping the aliased joined entity (fruit) however seems only to be possible by hacking a customized read functionality, which would better be provided via R2dbcConverter. I have seen that functionality for reading values with column prefixes is available internally via MappingR2dbcConverter#readFrom but could not find a way to make use of it for my use case.
The text was updated successfully, but these errors were encountered:
We already use a prefix internally and with #288, we plan to extend on reading objects with a prefix applied so it makes sense to surface the functionality a bit more. We should extend EntityRowMapper and R2dbcConverter to accept both column prefixes.
There is an example project available here
I used the r2dbc mapping functionality to map joined entities via alias prefixes:
I can easily map the root entity (tree) via
read(type, row, rowMetadata)
. Mapping the aliased joined entity (fruit) however seems only to be possible by hacking a customized read functionality, which would better be provided via R2dbcConverter. I have seen that functionality for reading values with column prefixes is available internally viaMappingR2dbcConverter#readFrom
but could not find a way to make use of it for my use case.The text was updated successfully, but these errors were encountered: