| Caching by natural ID is already supported (see http://docs.jboss.org/hibernate/orm/5.1/userguide/html_single/Hibernate_User_Guide.html#naturalid-mutability-caching) Unfortunately there are some restrictions on natural IDs, so it is an incomplete solution for the general problem: an entity can only have 1 natural ID (which can include 1 or more attributes); the natural ID must be defined at the root of an entity hierarchy. A general solution would need to support: caching entities by multiple foreign keys (one for each one-to-one association); allow caching entities by foreign keys that are defined in the root of the entity hierarchy, as well as in subclasses. Something to keep in mind is that caching by IDs performs well because an entity's ID is immutable. One-to-one associations based on a foreign key is mutable, and there will be a cost in performance to deal with associations that change. There should be a way to avoid checking for changes when the application "knows" there are no changes, similar to what is described for natural IDs. See SimpleNaturalIdLoadAccess#setSynchronizationEnabled. I have tentatively set the fix version for HHH-11124 Open to 6.0.Beta1. We will need to investigate further if this is really feasible. |