| See topic: https://forum.hibernate.org/viewtopic.php?f=1&t=1042964&p=2488756#p2488756 If a provided named query and the (always) desired entitygraph for this named query are known and fixed at deploy-time, then the HqlQueryPlan should be cached and not recalculated each time. After all, named queries are designed / meant to be processed at deploy time, and by setting an entity graph hint at runtime, this advantage over 'normal' queries seems to be minimized, if any!? I've tried, but to no avail...: Code: @NamedEntityGraph(name = "InlegJpa", includeAllAttributes = true) @NamedQueries({ @NamedQuery(name = "InlegJpa.queryInleggenMetPeriodiekOpbouwVoorKlant", query = "SELECT DISTINCT inleg FROM InlegJpa as inleg, " + "InlegBetaalherkomstJpa as herkomst " + "WHERE inleg.pk.verzekerdeIdentificatie = herkomst.pk.klantnummerInleg " + "AND inleg.pk.sppProductIdentificatie = herkomst.pk.sppIdInleg " + "AND inleg.pk.polisOnderdeelNummer = herkomst.pk.polisonderdeelNummerInleg " + "AND inleg.pk.keynummer = herkomst.pk.keynummerInleg " + "AND inleg.pk.verzekerdeIdentificatie = :persoonId " + "AND inleg.datumVerificatie IS NOT NULL " + "AND inleg.datumEindeRegistratie IS NULL", hints = { @QueryHint(name = "javax.persistence.loadgraph", value = "InlegJpa"), @QueryHint(name = "org.hibernate.readOnly", value = "true") } ), ... Debugging into Hibernate code, I found that the QueryHint on readonly gets processed and set to true, but the loadgraph hint doesn't. Moreover, the org.hibernate.engine.spi.NamedQueryDefinition class doesn't have an attribute to hold a reference to an entity graph instance. |