Traditionally, the parent-side {{@OneToOne}} association will always fetch the child association eagerly.
For optional associations, this makes a lot of sense because we have to know whether we need a null or a Proxy.
For non-optional associations, we don't know the child entity identifier, so we also need a query to populate the Proxy with the least information possible. However, if the association is using {{@MapsId}}, we know that both the parent and the child are going to share the same identifier, in which case the secondary select is not needed anymore.
This is even more dramatic if the user selects N parent entities with a JPQL query, and she forgets to fetch the child side. Another N secondary queries will be generated, leading to a N+1 query issue.
This optimization for {{@MapsId}} cases will allow us to circumvent this secondary select problem without having to use bytecode enhancement. |
|