Hi
I'm having a problem understanding what is happening when I save an object with collections. I've had a good dig around the documentation and the FAQs but think I'm perhaps just making the wrong assumptions.
If you look at the mapping files below, when I save a LearningObjectVO (subclass of PackagePartVO) then everything is saved correctly in the database, good start! However when I then view the contents of the LearningObjectVO I was expecting the learningObjectId field on the MetadataValueVO to be populated with the id from the LearningObjectVO but it isn't. If I get the LearningObjectVO out of the database again then everything is fine and dandy. My question is should I have to do this, I wouldn't have expected to have to select the object again once I'd carried out the save.
Details of the version, mapping files etc ...
Hibernate version: 2.1.6
Mapping documents:
Code:
<class name="com.intrallect.intralibrary.vo.MetadataValueVO" table="metadata_values">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="identity" />
</id>
<property name="value"/>
<property name="learningObjectId" column="lnob_id"/>
<property name="languageId" column="lgst_id"/>
<property name="xpath" column="xpath"/>
<property name="sourceId" column="source_id"/>
<many-to-one name="metadataEntry" class="com.intrallect.intralibrary.vo.MetadataEntryVO" column="metadata_id" />
</class>
Code:
<class name="com.intrallect.intralibrary.vo.PackagePartVO" table="package_part" discriminator-value="PACKAGE_PART">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="identity" />
</id>
<discriminator column="hibernate_discriminator" type="string"/>
<property name="packagePartType" column="package_part_type" not-null="true"/>
<property name="parentId" column="parent_id"/>
<property name="lastUpdated" column="last_updated"/>
<property name="fileName" column="file_name"/>
<property name="manifestVersion" column="version"/>
<property name="manifestId" column="manifest_id"/>
<property name="type" column="type" not-null="true"/>
<property name="location" column="location"/>
<map name="metadataMap" cascade="all-delete-orphan">
<key column="lnob_id"/>
<index column="xpath" type="string"/>
<one-to-many class="com.intrallect.intralibrary.vo.MetadataValueVO" />
</map>
<!-- LearningObjectVO -->
<subclass name="com.intrallect.intralibrary.vo.LearningObjectVO" discriminator-value="LEARNING_OBJECT">
<bag name="organizations" cascade="all">
<key column="lnob_id"/>
<one-to-many class="com.intrallect.intralibrary.vo.OrganizationNodeVO" />
</bag>
<bag name="learningItems" cascade="all">
<key column="lnob_id"/>
<one-to-many class="com.intrallect.intralibrary.vo.LearningItemVO" />
</bag>
<bag name="resources" cascade="all">
<key column="lnob_id"/>
<one-to-many class="com.intrallect.intralibrary.vo.ResourceVO" />
</bag>
<bag name="childLearningObjects" cascade="all-delete-orphan" >
<key column="parent_id"/>
<one-to-many class="com.intrallect.intralibrary.vo.LearningObjectVO" />
</bag>
<one-to-one name="learningObjectInfo" class="com.intrallect.intralibrary.vo.LearningObjectInfoVO" property-ref="learningObject" cascade="all"/>
</subclass>
<!-- LearningObjectVO -->
</class>
Code between sessionFactory.openSession() and session.close():Code:
try
{
beginTransaction();
currentSession().saveOrUpdate( hibernateVO );
commitTransaction();
}
catch ( HibernateException e )
{
rollbackTransaction();
throw new IntegrationException( e );
}
finally
{
closeSession();
}
Full stack trace of any exception that occurs: No Exception
Name and version of the database you are using: MySQL 4.0.20