2 Replies Latest reply on Oct 15, 2008 8:53 AM by Chip Schoch

    One-to-Many mapping issue

    Chip Schoch Novice

      I have a situation where I have a one-to-many:

      Document 1 ---> m DocumentVersion.

      The document version has a composite-id.

      <class name="com.eLynx.Core.Database.Entity.DocumentVersion"
       table="DocumentVersion"
       lazy="false">
      
       <composite-id >
       <key-many-to-one name="document"
       column="ContentId"
       class="com.eLynx.Core.Database.Entity.Document"/>
      
       <key-property name="version" column="Version" type="int"/>
       <key-property name="mimeType" column="MimeType" type="string"/>
       </composite-id>
      
       <timestamp name="CreationDate" source="db" />
      
       <property name="CSFileId" type="long">
       <column name="CSFileId" not-null="true"/>
       </property>
      
      </class>


      The Document class is a subclass:

      <!-- Document subclass definition -->
      <subclass name="com.eLynx.Core.Database.Entity.Document"
       discriminator-value="D">
      
       <list name="DocumentVersions"
       table="DocumentVersion"
       inverse="true"
       cascade="all">
      
       <key column="ContentId"/>
       <index column="version"/>
       <one-to-many class="com.eLynx.Core.Database.Entity.DocumentVersion"/
       </list>
      
      </subclass>


      I have test data where a document has one version. When I do the load from:

      Document root = (Document) session.load (Document.class, 146L);
      List<DocumentVersion> versions = root.getDocumentVersions();
      


      then examine the list in the debugger I see:
      [null, com.eLynx.Core.Database.Entity.DocumentVersion@a576d0d9]


      I cannot, for the life of me, figure out why I have that null in the first position. Anyone have any ideas? Thanks in advance.