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.  [ 3 posts ] 
Author Message
 Post subject: Very Confused regarding one-to-one mapping
PostPosted: Sat Apr 07, 2007 11:14 pm 
Newbie

Joined: Sat Apr 07, 2007 8:02 pm
Posts: 4
I am trying to get a one to one mapping working correctly and no matter what I do, I can't get the saves to cascade correctly.

I have an Account object and a BillingAddress object that is a subclass of an Address object.

Whenever I try to issue a save on the Account, the BillingAddress persistence action is an update instead of an insert.

I am obviously doing something wrong, but I can't figure out what it might be.

The Account Object:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="[Apptik_Security].[dbo]" assembly="ApptikFramework.Domain" namespace="ApptikFramework.Domain.Entities.Security" >
   <class name = "Account"   table= "[Account]" select-before-update="true">
      <id name="_system_ObjectId" access="field"  column="System_ObjectId"  type="System.Guid"     >
         <generator class="guid" />
      </id>
      <version column="System_Version" name="System_Version" type="System.Int64" unsaved-value="negative" />
      <many-to-one name="BillAddress" class="ApptikFramework.Domain.Entities.Security.BillingAddress, ApptikFramework.Domain" column="BillAddressId" unique="true" cascade="all-delete-orphan" />

   </class>
</hibernate-mapping>


The Address object:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="[Apptik_Security].[dbo]" assembly="ApptikFramework.Domain" namespace="ApptikFramework.Domain.Entities.Security" >
   <class name = "Address"   table= "[Address]" select-before-update="true" discriminator-value="0"  >
      <id name="_system_ObjectId" access="field"  column="System_ObjectId"  type="System.Guid" >
         <generator class="guid" />
      </id>
      
      <discriminator column="AddressType" type="System.Byte"   />

      <version column="System_Version" name="System_Version" type="System.Int64" unsaved-value="negative" />

      <subclass discriminator-value="1" name="ApptikFramework.Domain.Entities.Security.BillingAddress, ApptikFramework.Domain">
      </subclass>
      <subclass discriminator-value="2" name="ApptikFramework.Domain.Entities.Security.MailingAddress, ApptikFramework.Domain"  />
   </class>
</hibernate-mapping>

When I issue a save on the above, the account gets INSERTed BUT the address object SQL that is executed is an UPDATE statement and not an insert statement.


Any help is greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 08, 2007 6:00 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I think you need to set the 'unsaved-value' attribute on the Id of your Address mapping to the equivalent of Guid.Empty:

Code:
unsaved-value="00000000-0000-0000-0000-000000000000"


Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 08, 2007 9:08 am 
Newbie

Joined: Sat Apr 07, 2007 8:02 pm
Posts: 4
merge_s.rottem wrote:
I think you need to set the 'unsaved-value' attribute on the Id of your Address mapping to the equivalent of Guid.Empty:

Code:
unsaved-value="00000000-0000-0000-0000-000000000000"



Same result. I also added optimistic lock to both classes, removed the unassigned value on the version, turned the id to assigned and tried assigning the IDs myself but same result each time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.