Hi guys,
I have a User parent class which has a Set of UserAccessRights objects.
I want to dynamically change the way I load the User with or without
the Set of UserAccessRights objects initialized.
So I set the lazy attribute in the User mapping xml file to true as below.
Mapping documents: <set name="userAccessRightSet" lazy="true" table="user_access_rights" cascade="save-update"> <key column="user_id"/> <composite-element class="com.UserAccessRights"> <parent name="User"/> <property name="role" column="user_role" type="integer"/> <many-to-one name="fileBusinessEntity" class="com.FileBusinessEntity" column="file_id" not-null="true" cascade="none"/> </composite-element> </set>
Note: the UserAccessRights class is mapped as Composite-Element.
In my code I load the User as below:
Code between sessionFactory.openSession() and session.close(): Criteria crit = session.createCriteria(User.class); crit.add(Expression.eq("userId",userId)); crit.setFetchMode("userAccessRightSet",FetchMode.EAGER); user = (User) crit.uniqueResult();
I use the EAGER FetchMode.
The problem is that the FetchMode.EAGER does not override the lazy attribute in the User mapping xml file and the UserAccessRights Set is not initialized.
So where the problem could be ?
How could I override dynamically the lazy attribute in the mapping xml file ?
Am I missing something ?
Thank you.
Skyrose.
Hibernate version: 2.1
|