this may be more a JPA question than purely Hibernate related.
Say I have an @Entity A which contains a reference to another @Entity B (or worse, a List of other @Entitys).
JPA will generate first a query to retrieve A:
Code:
SELECT ID, FIELD1, B_ID FROM A WHERE ID=:ID
After which it will generate another query to retrieve the matching B:
Code:
SELECT ID, FIELD1 FROM B WHERE ID=:ID
passing in the retrieved ID.
-- SQL not identical to generated, just for documentation
Is there any way to optimise this to the SQL any human would write?:
Code:
SELECT A.ID, A.FIELD1, B.ID, B.FIELD1 FROM A A, B B WHERE B.ID = A.B_ID
Would save a lot of database roundtrips, which can be a real performance boost.