If you look more closely it actually shows just the initial query being performed, no join. Obviously to join fetch an assoctiation via a native SQL query, that SQL query is going to need to specify the join
And for this reason it's wrong. Cause the query has a join: "JOIN Person pr ON ph.person_id = pr.id", Phone.class ) and the test case too: + "join Person p " + "on ph.person_id = p.id ".
the documentation does not suggest that the 475 example specifically handles many-to-one associations avoiding extra roundtrip to initializing them.
Indeed. I made a confusion because the example is just after this: "It is possible to eagerly join the Phone and the Person entities to avoid the possible extra roundtrip for initializing the many-to-one association." Maybe this paragraph should be put after example 475. Maybe example 475 is just illustrating this note: "The additional columns will automatically be returned when using the * notation." But if it's the case there is no need for join.
As far as JPA's native SQL support, the JPA spec explicitly says that "a SqlResultSetMapping metadata definition must be provided to specify the entity mapping" in such cases.
I think one example is missing in the documentation. It is the JPA version of example 476, which I wrongly believed to be example 475. I could use example 476, except for the fact that everything is now deprecated. |