Here I read it should be possible using the NamedEntityGraph
, but when the graph gets passed as param to say panache list(queryString, params)
with the key being jakarta.persistence.fetchgraph
it throws with unexpected param error.
open val entityGraphName: String? = null
protected abstract val klass: Class<EntityType>
suspend fun list(): List<EntityType> {
return list("entityTenantId = :tenantId", getQueryParams().and("tenantId", tenantId.id)).awaitSuspending()
}
private suspend fun getGraph(): EntityGraph<EntityType>? {
return if (entityGraphName == null) {
null
} else {
session.map { s ->
s.getEntityGraph(klass, entityGraphName)
}.awaitSuspending()
}
}
protected suspend fun getQueryParams(): Parameters {
val graph = getGraph()
return if (graph == null) {
Parameters()
} else {
// https://www.baeldung.com/jpa-entity-graph
Parameters.with("jakarta.persistence.fetchgraph", graph)
}
}
I want to avoid writing the queries myself, as the repository inherits from a base class which methods would need to be then overridden.