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.  [ 2 posts ] 
Author Message
 Post subject: one-to-many foreign key based association problem
PostPosted: Wed Oct 10, 2007 3:13 pm 
Newbie

Joined: Thu Sep 20, 2007 10:34 am
Posts: 2
Dear all,

I have a one-to-many foreign key associated tables auto populate problem. (I want all the associated tables to get the Parent table's PK. My 1 Parent has 3 children).
Code:
<hibernate-mapping>
  <class name="TransactionTableVO" table="TRANSACTION_TABLE">
      <id name="txnId" type="java.lang.String" column="TRANSACTION_ID" >
        <generator class="sequence">
           <param name="sequence">cdhc.transaction_id_seq</param>
        </generator>
   </id>
   
   <set name="txnSharedAccSet" cascade="save-update">
      <key column="TRANSACTION_ID"/>
      <one-to-many class="TxnSharedAccumulatorVO" />
   </set>
...
and the TransactionTableVO class has this:
   private Set txnSharedAccSet;
   
   public Set getTxnSharedAccSet() {
      return txnSharedAccSet;
   }
   public void setTxnSharedAccSet(Set txnSharedAccSet) {
      this.txnSharedAccSet = txnSharedAccSet;
   }

Code:
<hibernate-mapping>
  <class name="TxnSharedAccumulatorVO" table="TXN_SHARED_ACCUMULATOR">
   <id name="txnId" column="TRANSACTION_ID" >
   <generator class="foreign">
      <param name="property">txnTbleVo</param>   
    </generator>
  </id>
 
  <many-to-one name="txnTbleVo" class="TransactionTableVO" />
...


And of course, it does not work!!

I am setting the TransactionTableVO's values, which includes the txnSharedAccSet. Is there anything that I"m missing please?

Thanks a lot for your help!
-Vg


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 11, 2007 12:02 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Don't call setTxnSharedAccSet(), only hibernate may do that. Use getTxnSharedAccSet().add(), addAll(), or whatever. In your TransactionTableVO constructor (or field initializer), create an appropriate set. That set is used only when creating a new TransactionTableVO, normally hibernate will call setTxnSharedAccSet() to replace that.

If TxnSharedAccumulatorVOs are independent objects, then define the txnSharedAccSet mapping as inverse="true" and the key not-null="true". If the TxnSharedAccumulatorVOs are dependent objects, change the cascade to all-delete-orphan and ensure that no code ever calls session.delete() on a TxnSharedAccumulatorVO.

_________________
Code tags are your friend. Know them and use them.


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

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.