I have a big problem. I have a recursive many to many asociation and i get a LazyInitializationException when i access to the lazy collection. My class is Perfil(in spanish) and this is its xbm.xml file:
Code:
<hibernate-mapping package="es.elsendero.comismar.to.acceso">
<class name="PerfilTO" table="perfil">
<id name="id" type="int">
<column name="id" length="4" not-null="true" unique="true" sql-type="int4" />
<generator class="sequence" >
<param name="sequence">S_PERFIL</param>
</generator>
</id>
<version name="version" type="int">
<column name="version" length="4" sql-type="int4"/>
</version>
<property name="nombre" type="java.lang.String">
<column name="nombre" length="50" sql-type="varchar"/>
...
</property>
<set name="childs" table="perfileschildsparents" lazy="true">
<key>
<column name="idParent" length="4" sql-type="int4" />
</key>
<many-to-many class="PerfilTO" column="idChild"/>
</set>
<set name="parents" table="perfileschildsparents" inverse="true" lazy="true">
<key>
<column name="idChild" length="4" sql-type="int4" />
</key>
<many-to-many class="PerfilTO" column="idParent"/>
</set>
</class>
</hibernate-mapping>
Hibernate generates two tables in the database. The table perfil and the table perfileschildsparents to manage de many to many relation. It looks ok, but something fails.
When I travel across the tree, Hibernate throws a LazyInitializationException when I access to a Perfil that hasnĀ“t got childs, but not always. Sometimes, I access to a Perfil without childs and its ok. The application works randomly. This it's insane!!!. I use the OpenSessionInView pattern with a Filter. I have copied de filter and the HibernateUtil class from the caveat emptor example application to test and I this they are ok.
Somebody has implemented this type of relation???????
Is the file correct????
I need your help.
Thanks!!