Hello everyone,
I posted a topic regarding a weird behavior with a property. I explained that if earlier in the code I made some call like System.out.println(obj.getForward()); the system worked perfectly, otherwise, my struts app would crash later on in a jsp because obj.getForward() returned null (where in fact It isn't null). I thought (and a reply came with the same answer), that it had to do with the lazy initialization of the object. The problem is that the property I'm talking about is a String not a collection, and as far as I know, lazy fetching of individual properties is default to false. (paranoid as I am, I set it to false, and still the same result). Here is the mapping of the Privilege class and others.
Code:
<hibernate-mapping>
<class name="MPrivilege" table="T_PRIVILEGE">
<id name="id" type="int" unsaved-value="0">
<generator class="increment"/>
</id>
<property name="name"/>
<property name="forward"/>
<bag name="rolPrivilegios" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="privilege_id"/>
<one-to-many class="MRolPrivilege"/>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="MRolPrivilege" table="T_ROL_PRIVILEGE">
<id name="id" type="int" unsaved-value="0">
<generator class="increment"/>
</id>
<many-to-one name="privilegioRef" class="MPrivilege" column="privilege_id"/>
<many-to-one name="rolRef" class="MRol" column="rol_id"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="MRol" table="T_ROL">
<id name="id" type="int" unsaved-value="0">
<generator class="increment"/>
</id>
<property name="nombre"/>
<bag name="rolPrivilege" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="rol_id"/>
<one-to-many class="MRolPrivilege"/>
</bag>
</class>
</hibernate-mapping>
On a Struts Action this is the relevant code
Code:
Iterator itt = rol.getPrivileges().iterator();
while (itt.hasNext()) {
MPrivilege privilege = (MPrivilege) itt.next();
menuElements.add(privilege);
}
And finally in a jsp I iterate through menuElements vector, and print the privelege.getForward().
Any help is appreciate it
Thanx in advance.