-->
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-one mapping cascade error
PostPosted: Fri Dec 18, 2009 12:13 am 
Newbie

Joined: Thu Dec 10, 2009 4:14 pm
Posts: 1
I have an Order_Headers schema that has PK order_id. I also have have another table Order_Addresses that has the same PK as the Order_Headers table, it also has a FK constraint on the order_id column of the Order_Addresses table referencing the order_id column in the Order_Headers table.

I have 2 classes OrderHeader and OrderAddress and I have the following entries in the mappings,

Code:
<class name="OrderHeader" schema="user" table="ORDER_HEADERS">
   <id  name="orderId" type="long" column="ORDER_ID" length="22" >
            <generator class="sequence">
      <param name="sequence">ORDER_SEQ</param>
       </generator>
   </id>
       <property name="sentFlag" type="string" column="SENT_FLAG" length="1"  />
       <one-to-one name="orderAddress" constrained="true" class="OrderAddress" cascade="all"/>
</class>

<class name="OrderAddress" schema="user" table="ORDER_HEADERS">
       <id name="addressId" column="ORDER_ID">
          <generator class="foreign">
         <param name="property">orderHeader</param>
      </generator>
   </id>
        <property name="line1"    type="string" column="LINE1" length="50" />
        <property name="line2" type="string" column="LINE2" length="50" />
   <one-to-one constrained="true" name="orderHeader"    class="OrderHeader" />
</class>


But I get the following error when trying to save a OrderHeader object,

org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property: orderHeader

What do I have to do to create the associations correctly?


Top
 Profile  
 
 Post subject: Re: One-to-one mapping cascade error
PostPosted: Fri Dec 18, 2009 5:25 pm 
Newbie

Joined: Wed Oct 21, 2009 7:33 am
Posts: 11
You have two OrderHeader and one OrderAdress. The way how I see it is for you to use one-to-many association not one-to-one, OrderAddress has one or more OrderHeader. If you can explain to me what an OrderHeader is I might be able to see it clearly what you are trying to do.


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.