hibernate config file is defined as below...
Code:
<hibernate-mapping package="com.onebeacon.diarytracking.ormapping.domain">
<class name="UserRoles" table="UserRoles">
<composite-id name="comp_id" class="UserRolesPK">
<key-property name="Role_CDE" column="Role_CDE" type="java.lang.String" length="25" />
<key-property name="Novell_ID" column="Novell_ID" type="java.lang.String" length="8" />
</composite-id>
<property name="Role_CDE" column="Role_CDE" type="java.lang.String" length="25" lazy="false" insert="false" update="false" />
<property name="PrimaryRole_IND" column="PrimaryRole_IND" type="java.lang.Byte" length="1" lazy="true" />
<property name="Novell_ID" column="Novell_ID" type="java.lang.String" length="8" lazy="false" insert="false" update="false" />
</class>
<sql-query name="UserRoles.getUserRoles">
<return class="UserRoles" />
<![CDATA[SELECT Novell_ID, Role_CDE, PrimaryRole_IND FROM UserRoles WHERE Novell_ID =:Novell_ID]]>
</sql-query>
</hibernate-mapping>
Using ANT script, UserRoles class is modified for runtime bytecode interception.
Now my question is - when I execute "UserRoles.getUserRoles" sql-query of this mapping, does it populate PrimaryRole_IND inside UserRoles class, even though PrimaryRole_IND is marked as lazy=true ?
After running multiple tests, I came to a conclusion that lazy properties are ignored when mapping sql-query resultset to POJO class. And as a result, when a getter is invoked for lazy property, it again executes another sql query to get the value for that lazy property. Is my understanding correct? If yes, how do we force Hibernate to map the resultset to POJO including lazy properties(as long as they are part of the sql projection)
Please help !!