Hi,
I am using dynamic model to fetch data.
entity.hbm.xml:
============
<hibernate-mapping default-lazy="false">
<class entity-name="en_table1" table="table1">
<id name="tab_id1" column="tab_id1" type="integer"/>
<property name="tab_name1" column="tab_name1" type="string" />
<set name="en_table2s" fetch="join" lazy="false">
<key column="tab_id1"/>
<one-to-many class="en_table2"/>
</set>
</class>
<class entity-name="en_table2" table="table2">
<id name="tab_id2" column="tab_id2" type="integer"/>
<property name="tab_name2" column="tab_name2" type="string" />
<set name="en_table3s" fetch="join" lazy="false">
<key column="tab_id2"/>
<one-to-many class="en_table3"/>
</set>
</class>
<class entity-name="en_table3" table="table3">
<id name="tab_id3" column="tab_id3" type="integer"/>
<property name="tab_name3" column="tab_name3" type="string" />
</class>
</hibernate-mapping>
Data Access Code:
================
Object o=session.get("en_table1",1);
Getting error:
================
org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:363)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:434)
at java.util.HashMap$Entry.hashCode(Unknown Source)
at java.util.AbstractMap.hashCode(Unknown Source)
at java.util.HashMap.put(Unknown Source)
at java.util.HashSet.add(Unknown Source)...........
#####
The problem arises from the second level Set (here, 'set name="en_table3s"' ). For first level set only('set name="en_table2s"') the problem doesn't arise.
Though can be solved by:
<set name="en_table3s" fetch="select" lazy="false">. But, I have to use fetch="join".
So, what should I do now? Please help.
Hibernate Version: hibernate-distribution-3.3.1.GA
Database: Oracle 10g
_________________ Prosenjit Chakraborty
|