Hi!
Given objects my.domain.ObjectA and my.domain.ObjectB. They have a many-to-one relation, where ObjectA contains a List of ObjectB, and ObjectB contains a reference to ObjectA. It's mapped like this:
Code:
<class name="my.domain.ObjectA" table="TABLE_A">
<id name="id" type="java.lang.Long" access="field">
<column name="IDE_TABLE_A" precision="9" scale="0" />
<generator class="identity" />
</id>
<bag name="listOfObjectB" inverse="true" cascade="save-update, delete">
<key>
<column name="IDE_TABLE_A" not-null="true" />
</key>
<one-to-many class="my.domain.ObjectB" />
</bag>
</class>
Code:
<class name="my.domain.ObjectB" table="TABLE_B">
<id name="id" type="java.lang.Long" access="field">
<column name="IDE_TABLE_B" precision="9" scale="0" />
<generator class="identity" />
</id>
<many-to-one name="objectA" class="my.domain.ObjectA">
<column name="IDE_TABLE_A" />
</many-to-one>
</class>
Now for the question: A service class receives as input a detached ObjectA, where the listOfObjectB may be null, even if the database TABLE_B contains rows with FK relations to rows in TABLE_A. Now, before manipulating and calling saveOrUpdate() on the ObjectA instance, I would like to make sure that the listOfObjectB is loaded and initialized with the correct data from TABLE_B. What would be the best way to do this?
Be aware that the data in the instance of ObjectA may be different from the data in TABLE_A, so I do not want to load ObjectA again. I only want to load the list of ObjectBs.