The SQL Hibernate generates for loading an Employee is:
select mapsidprox0_.id as id1_0_0_,
mapsidprox0_.name as name2_0_0_,
mapsidprox1_.employer_id as employer2_1_1_,
mapsidprox1_.info as info1_1_1_
from Employer mapsidprox0_
inner join EmployerInfo mapsidprox1_
on mapsidprox0_.id=mapsidprox1_.employer_id
where mapsidprox0_.id=?
When bytecode enhancement is disabled, the Employer#employeeInfo is loaded eagerly. When bytecode enhancement is enabled, it takes an extra query to initialize Employer#employeeInfo:
select mapsidprox0_.employer_id as employer2_1_0_,
mapsidprox0_.info as info1_1_0_
from EmployerInfo mapsidprox0_
where mapsidprox0_.employer_id=?
We know from the model that the ID for Employee#employeeInfo is the same as Employee, so the inner join is unnecessary, and Hibernate should be able to make the association lazy, with or without bytecode enhancement. |