-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Recursion ,DB2
PostPosted: Thu Apr 14, 2011 12:35 pm 
Newbie

Joined: Tue Apr 12, 2011 2:27 am
Posts: 1
Hello everyone, i have a problem with a self referencing table using composite keys.
I am trying to make a tree of Assignment objects/nodes.

The Object is ... (i am leaving out getters & setters)
Code:
public abstract class AssignmentImpl extends
AbstractModificationRecordPo<AssignmentKey> implements Assignment {

   private static final long serialVersionUID = -1944000056837918634L;
   private Float cessionPercentage;
   private String comments;

   private Assignee assignee;
   [b]private List<Assignment> children[/b];
   private Long reinsurerAmount;
   private Long reinsurerCommition;
   private Long reinsurerTeaa;
   private short level;
   [b]private Assignment parent[/b];
}


My mapping is

Code:
<class name="Assignment" table="TBLCASM" dynamic-insert="true"
      dynamic-update="true">
      <composite-id name="key" class="AssignmentKey">
         <key-property name="assignmentId" type="long">
            <column name="ASSIGNMENTNO" sql-type="DECIMAL(10,0)" index="IXLCASMNT"
               not-null="true" default="0"></column>
         </key-property>
         <key-property name="branchId" type="integer">
            <column name="BRANCHID" sql-type="SMALLINT" index="IXLCASMNT"
               not-null="true" default="0"></column>
         </key-property>
         <key-property name="policyNo" type="long">
            <column name="POLICYNO" sql-type="DECIMAL(10,0)" index="IXLCASMNT"
               not-null="true" default="0"></column>
         </key-property>
         <key-property name="legerNo" type="long">
            <column name="LEGERNO" sql-type="DECIMAL(10,0)" index="IXLCASMNT"
               not-null="true" default="0"></column>
         </key-property>
         <key-property name="companyId" type="integer">
            <column name="COMPANYID" sql-type="SMALLINT" index="IXLCASMNT"
               not-null="true" default="0"></column>
         </key-property>
         <key-property name="issueDate" type="date">
            <column name="ISSUEDATE" sql-type="DATE" index="IXLCASMNT"
               not-null="true"></column>
         </key-property>
      </composite-id>
      <timestamp name="lastModified" column="DATEMOD"
         unsaved-value="null"></timestamp>
      <property name="lastModifiedBy" type="string" not-null="true">
         <column name="USERMOD" sql-type="CHAR(20)" not-null="false"></column>
      </property>
      <property name="reinsurerAmount" type="long">
         <column name="REINAMOUNT" sql-type="DECIMAL(13,2)" not-null="true"></column>
      </property>
      <property name="reinsurerCommition" type="long">
         <column name="REINCOMM" sql-type="DECIMAL(13,2)" not-null="true"></column>
      </property>
      <property name="reinsurerTeaa" type="long">
         <column name="REINTEAA" sql-type="DECIMAL(13,2)" not-null="true"></column>
      </property>
      <property name="level" type="short">
         <column name="LVL" sql-type="SMALLINT" not-null="true"></column>
      </property>
      <many-to-one name="parent" class="Assignment" lazy="false"
         not-null="false" insert="false" update="false" >
         <column name="PARENTID" not-null="false" sql-type="DECIMAL(10,0)"></column>
         <column name="PARENTBRANCH" not-null="false" sql-type="SMALLINT"></column>
         <column name="PARENTPOLICY" not-null="false" sql-type="DECIMAL(10,0)"></column>
         <column name="PARENTLEGER" not-null="false" sql-type="DECIMAL(10,0)"></column>
         <column name="PARENTCOMP" not-null="false" sql-type="SMALLINT"></column>
         <column name="PARENTISS" not-null="false" sql-type="DATE"></column>
      </many-to-one>
      <bag name="children" lazy="false" cascade="all">
         <key>
            <column name="PARENTID" not-null="false" sql-type="DECIMAL(10,0)"></column>
            <column name="PARENTBRANCH" not-null="false" sql-type="SMALLINT"></column>
            <column name="PARENTPOLICY" not-null="false" sql-type="DECIMAL(10,0)"></column>
            <column name="PARENTLEGER" not-null="false" sql-type="DECIMAL(10,0)"></column>
            <column name="PARENTCOMP" not-null="false" sql-type="SMALLINT"></column>
            <column name="PARENTISS" not-null="false" sql-type="DATE"></column>
         </key>
         <one-to-many class="Assignment" />
      </bag>
      <many-to-one name="assignee" foreign-key="FKASASN" class="Assignee"
         not-null="true" cascade="none">
         <column name="REINSCODE" sql-type="DECIMAL(10,0)"></column>
      </many-to-one>
   </class>


I thought i made this this work and tested it in Derby, but when i tried to create the self referencing foreign-key in DB2,
the mainframe is strict and complains that foreign keys should be primary-keys (parent-keys).
Is there any way to make this work otherwise to create a tree, in hibernate? I used the Node.hbm.xml example in hibernate examples, but i don't know if it can be done this way,
Thanx in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.