Hibernate version:
2.1.8
Mapping documents:
<class name="edu.uga.ais.pdia.domain.User" schema="PDIA" table="DIAB99U" mutable="false">
<id name="username" column="DIAB99U_CDMYID" type="edu.uga.ais.pdia.dao.impl.CharTrimType">
<generator class="assigned"/>
</id>
<set name="userAccess" lazy="true" inverse="true" access="field">
<key column="DIAB99D_CDUSER"/>
<one-to-many class="edu.uga.ais.pdia.domain.UserAccess"/>
</set>
</class>
<class name="edu.uga.ais.pdia.domain.UserAccess" schema="PDIA" table="DIAB99D" mutable="false">
<composite-id>
<key-property name="username" column="DIAB99D_CDUSER" type="edu.uga.ais.pdia.dao.impl.CharTrimType"/>
<key-many-to-one name="department" column="DIAB99D_NODEPT"/>
<key-property name="category" column="DIAB99D_CDCATG" type="edu.uga.ais.pdia.dao.impl.CategoryUserType"/>
</composite-id>
<property name="privilege" column="DIAB99D_CDALTR" type="edu.uga.ais.pdia.dao.impl.PrivilegeUserType"/>
</class>
<class name="edu.uga.ais.pdia.domain.Department" schema="PCFA" table="BCFA20C" mutable="false">
<id name="number" column="NODEPT">
<generator class="assigned"/>
</id>
<property name="description" column="DSDEPT" type="edu.uga.ais.pdia.dao.impl.CharTrimType"/>
</class>
Code between sessionFactory.openSession() and session.close():
private static final String FIND_USER_NOTLAZY =
"from User user" +
" inner join fetch user.userAccess access" +
" inner join fetch access.department" +
" where user.username = :username";
List users = getHibernateTemplate().findByNamedParam(FIND_USER_NOTLAZY,"username",username);
The generated SQL (show_sql=true):
Hibernate: select user0_.DIAB99U_CDMYID as DIAB99U_1_0_, useraccess1_.DIAB99D_CDUSER as DIAB99D_1_1_, useraccess1_.DIAB99D_NODEPT as DIAB99D_2_1_, useraccess1_.DIAB99D_CDCATG as DIAB99D_3_1_, department2_.NODEPT as NODEPT2_, useraccess1_.DIAB99D_CDALTR as DIAB99D_4_1_, department2_.DSDEPT as DSDEPT2_, useraccess1_.DIAB99D_CDUSER as DIAB99D_1___, useraccess1_.DIAB99D_NODEPT as DIAB99D_2___, useraccess1_.DIAB99D_CDCATG as DIAB99D_3___ from PDIA.DIAB99U user0_ inner join PDIA.DIAB99D useraccess1_ on user0_.DIAB99U_CDMYID=useraccess1_.DIAB99D_CDUSER inner join PCFA.BCFA20C department2_ on useraccess1_.DIAB99D_NODEPT=department2_.NODEPT where (user0_.DIAB99U_CDMYID=? )
Hibernate: select department0_.NODEPT as NODEPT0_, department0_.DSDEPT as DSDEPT0_ from PCFA.BCFA20C department0_ where department0_.NODEPT=?
Hibernate: select department0_.NODEPT as NODEPT0_, department0_.DSDEPT as DSDEPT0_ from PCFA.BCFA20C department0_ where department0_.NODEPT=?
My Question :)
I might be understanding this wrong, but it would seem to me that the only one query would be needed to do this. The first query returns all the data that is needed to create the graph. Am I missing something?
Is is possible to load all data eagerly with these mappings?
|