We're using hibernate 2.0.1 with Oracle 9. There's a parent-child relation between Content and ContentLink - a Content is mapped to have a lazy list of ContentLinks. (I am attaching the mapping below.)
The problem is that the list is loaded every time as soon as the parent object is loaded via Session.load().
I thought the problem was with ContentLink that has a composite primary key (content_id, sequence_num), and the same sequence_num is used for List mapping. I have tried two things - changing List mapping to Set, and adding a synthetic primary key to ContentLink. Neither approach helped.
Now I am thinkging about trying the latest version of hibernate, but that is going to involve a lot of changes in our project, so I decided to check with you guys.
Also, I do have the full debug log, and it doesn't mention any "lazy" collections, just goes and loads everything. It's a long file, so I didn't attach it.
Thanks for your time,
Alex
Code:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.amg.condenet.style.content.domain.Content" table="CONTENT">
<id name="contentId" type="string" column="content_id" length="255">
<generator class="assigned"/>
</id>
<property name="body" column="body" type="com.amg.condenet.data.StringClobType" not-null="true"/>
<property name="title" column="title" type="string" not-null="true" length="512"/>
<property name="byline" column="byline" type="string" not-null="false" length="512"/>
<property name="subtitle" column="subtitle" type="string" not-null="false" length="512"/>
<property name="location" column="location" type="string" not-null="false" length="512"/>
<property name="overrideURL" column="override_url" type="string" not-null="false" length="512"/>
<property name="displayDate" column="display_date" type="timestamp" not-null="true"/>
<property name="expireDate" column="expire_date" type="timestamp" not-null="false"/>
<property name="liveDate" column="live_date" type="timestamp" not-null="false"/>
<property name="archived" column="is_archived" type="yes_no" not-null="true"/>
<many-to-one name="template"
column="template_id"
class="com.amg.condenet.style.content.domain.Template"
not-null="true"/>
<many-to-one name="contentType"
column="content_type_id"
class="com.amg.condenet.style.content.domain.ContentType"
not-null="true"/>
<many-to-one name="sourceType"
column="source_type_id"
class="com.amg.condenet.style.content.domain.SourceType"
not-null="true"/>
<list name="contentLinks" lazy="true" inverse="true" cascade="all">
<key column="content_id"/>
<index column="sequence_num"/>
<one-to-many class="com.amg.condenet.style.content.domain.ContentLink"/>
</list>
</class>
</hibernate-mapping>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<!-- com.amg.condenet.style.content.domain.ContentLink root -->
<class name="com.amg.condenet.style.content.domain.ContentLink" table="CONTENT_LINK">
<composite-id>
<key-many-to-one name="content" column="content_id" />
<key-property name="sequenceNum" column="sequence_num" type="integer"/>
</composite-id>
<many-to-one name="contentLinkType" column="content_link_type_id"/>
<many-to-one name="slideshow" column="slideshow_id"/>
<many-to-one name="photo" column="photo_id"/>
<property name="text" column="text" type="string" not-null="false" length="255"/>
<property name="link" column="link" type="string" not-null="false" length="255"/>
</class>
</hibernate-mapping>