pepelnm wrote:
try with:
Code:
<one-to-one name="people" fetch="join" lazy="false" />
<many-to-one name="group" fetch="join" column="tgroup" lazy="false" />
What's happened?
I get the same:
Code:
Hibernate: select user0_.id as id4_, user0_.tgroup as tgroup4_, user0_.login as login4_, user0_.password as password4_ from tuser user0_ where user0_.id=?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
Hibernate: select group0_.id as id0_0_, group0_.description as descript2_0_0_ from tgroup group0_ where group0_.id=?
I think that this configuration should be redundant, because, if I have fetch join, lazy should not be true in any case. Anyway, this configuration seems to be in favor of lazy="false". If I execute the following query without lazy="false" the SQL is like I show below:
HQL: from User user where user.id > 5 // I have 5 registries that matchs with it
Code:
Hibernate: select user0_.id as id4_, user0_.tgroup as tgroup4_, user0_.login as login4_, user0_.password as password4_ from tuser user0_ where user0_.id>?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
A note about it, groups are clearly loaded in lazy mode. If I not made access to a group, it is not load automatically in join as expected. So, if I put lazy="false", the SQL generated is:
Code:
Hibernate: select user0_.id as id4_, user0_.tgroup as tgroup4_, user0_.login as login4_, user0_.password as password4_ from tuser user0_ where user0_.id>?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
Hibernate: select group0_.id as id0_0_, group0_.description as descript2_0_0_ from tgroup group0_ where group0_.id=?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
Hibernate: select group0_.id as id0_0_, group0_.description as descript2_0_0_ from tgroup group0_ where group0_.id=?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
Hibernate: select group0_.id as id0_0_, group0_.description as descript2_0_0_ from tgroup group0_ where group0_.id=?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
Hibernate: select group0_.id as id0_0_, group0_.description as descript2_0_0_ from tgroup group0_ where group0_.id=?
Hibernate: select people0_.id as id2_0_, people0_.nome as nome2_0_, people0_.idade as idade2_0_ from People people0_ where people0_.id=?
Hibernate: select group0_.id as id0_0_, group0_.description as descript2_0_0_ from tgroup group0_ where group0_.id=?
As I said before, seems that lazy="false" override fetch="join". So, the question is, how to configure mappings to load one-to-one and many-to-one in join mode?
Kind Regards,