-->
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: Child mapping with composite-id
PostPosted: Mon Jul 23, 2007 8:18 am 
Newbie

Joined: Mon Jul 23, 2007 7:56 am
Posts: 1
Hi, I've got a problem with a parent / child relation, with the child having a composite-id. I use NHibernate 2.1 on SQL Server 2005.

Here are the mappings for my 2 entities :

The parent :
Code:
<class name="QuestionnaireTable" table="QUESTTABLE">
  <id name="Id">
    <column name="QTA_ID" sql-type="numeric" length="9" />
    <generator class= "identity" />
  </id>
  <property name="Code" column="QTA_CODE" type="string" length="15"/>
[...]
  <bag name="QuestionnaireStructureCols"  table="QUESTSTRUCTCOL" lazy="false" cascade="all-delete-orphan" >
    <key>
      <column name="QTA_ID" not-null="true"  />
    </key>
    <one-to-many class="QuestionnaireStructureCol" />
  </bag>
</class>




Child
Code:
  <class name="QuestionnaireStructureCol" table="QUESTSTRUCTCOL">
      <composite-id unsaved-value="any" >
        <key-property name="QuestionnaireTableId" column="QTA_ID" type="long" />
        <key-property name="ColNum" column="QSC_COL_NUM" type="long"/>
      </composite-id>
    <property name="Width" column="QSC_WIDTH" type="long" />
  </class>



I try to create a new object, filled with one element :

QuestionnaireTable q = new QuestionnaireTable();
q.QuestionnaireStructureCol = new List();

QuestionnaireStructureRow r = new QuestionnaireStructureRow();
r.ColNum = 1;

q.Add(r);
session.SaveOrUpdate(q);


I've got an error on the SaveOrUpdate, because the field "QTA_ID", which is part of the foreign key and the id of the child, is not updated..
For example, at first, all my objects have a "QTA_ID" equals to 0.
after SaveOrUpdate, my QuestionnaireTable has a QTA_ID = 90, but my object "QuestionnaireStructureRow" stay with a QTA_ID = 0, and the generated SQL crash
INSERT INTO QUEST_STRUCTURE_COL (QTA_ID, QSC_WIDTH, QSC_COL_NUM) VALUES (?, ?, ?, ?) --> QTA_ID is binded to 0.

Did I miss something ? I can't figure out what's the problem, thanxs in advance for any help !


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.