I have a 4 level set of parent child relationships that look essentially the same. The classes involved are Job, Run, Target and Spec. The parent child relationships are Job->Runs, Run->Targets, Target->Specs. The collection is a unidirectional (except for Job->Runs) list structure. I have a recursive method that copyCount() that gets called at Job and recurses down to Specs. So Job.copyCount() calls Run.copyCount() on all runs, calls Target.copyCount() on all targets, calls Spec.copyCount on all specs. Note, all of the lists have cascade=all, lazy=true.
Problem: If I create a Job with no Runs, Job.copyCount() gets the list and gets a valid (empty) iterator on the list of runs. Debugging, I find the runs list is "inititialized". If I create a Job with a Run and no Targets, Job.copyCount() calls Run.copyCount() (successfully) and then gets a valid (empty) iterator on the lists of targets. Debugging I find the targets list is "initialized". If I create a Job with a Run and a Target, when I call Job.copyCount(), everything works down to to the point of Target.copyCount()... It goes to get the Iterator (on what should be an empty list), and gets an unitialized collection error.
Why does this work down the chain of relationships but stop at the point of the Target->Specs relationship?
Debugging, I have watched the as the objects are getting instantiated from the database I noticed that as the database is setting the "list" on each object down to the Run->Targets list and it is getting initialized (even though i have lazy=true) as the objects are loaded and instantiated. But the Target->Specs list does not get initialized (I inspected the bag and it is set to unitialized). In addition, I wrote a checkInitialized() method that right before accessing it I go check and try to inititialize it, but that fails too... Any reason(s)??? This is a real tough one.
Hibernate version: 2.1.1
Mapping documents:
Code:
<hibernate-mapping>
<class name="com.gsk.legal.copy.bo.himpl.HIBCopyJob" table="COPY_JOB">
<id name="id" type="long" column="id">
<generator class="native"/>
</id>
<property name="name" column="NAME" type="string"/>
<bag name="copyRuns" table="COPY_JOB_COPY_RUNS_LIST"
cascade="all" lazy="true" inverse="true">
<key column="COPY_JOB_ID"/>
<one-to-many class="com.gsk.legal.copy.bo.himpl.HIBCopyRun"/>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.gsk.legal.copy.bo.himpl.HIBCopyRun" table="COPY_RUN">
<id name="id" type="long" column="id">
<generator class="native"/>
</id>
<property name="name" column="NAME" type="string"/>
<property name="stateStr" column="STATE_STR" type="string"/>
<property name="runStartDateLong" column="RUN_START_DATE_L" type="long"/>
<property name="runEndDateLong" column="RUN_END_DATE_L" type="long"/>
<many-to-one name="parentCopyJob" class="com.gsk.legal.copy.bo.himpl.HIBCopyJob"
column="COPY_JOB_ID"/>
<bag name="copyTargets" table="COPY_RUN_COPY_TARGETS_LIST"
cascade="all" lazy="true" inverse="false">
<key column="COPY_RUN_ID"/>
<one-to-many class="com.gsk.legal.copy.bo.himpl.HIBCopyTarget"/>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.gsk.legal.copy.bo.himpl.HIBCopyTarget" table="COPY_TARGET">
<id name="id" type="long" column="id">
<generator class="native"/>
</id>
<property name="URL" column="URL" type="string"/>
<many-to-one name="parentCopyRun" class="com.gsk.legal.copy.bo.himpl.HIBCopyRun"
column="COPY_RUN_ID"/>
<bag name="copySpecs" table="COPY_TARGET_COPY_SPECS_LIST"
cascade="all" lazy="true" inverse="false">
<key column="COPY_TARGET_ID"/>
<one-to-many class="com.gsk.legal.copy.bo.himpl.HIBCopySpec"/>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.gsk.legal.copy.bo.himpl.HIBCopySpec" table="COPY_SPEC">
<id name="id" type="long" column="id">
<generator class="native"/>
</id>
<property name="sourceSpec" column="SRC_SPEC" type="string"/>
<property name="destSpec" column="DEST_SPEC" type="string"/>
<property name="sizeInKB" column="SIZE_KB" type="integer"/>
<property name="copied" column="COPIED" type="boolean"/>
<many-to-one name="parentCopyTarget" class="com.gsk.legal.copy.bo.himpl.HIBCopyTarget"
column="COPY_TARGET_ID"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: