-->
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: Issue with mapping multiple one-to-one in same class
PostPosted: Tue Oct 04, 2005 4:50 am 
Im having a problem deleting all instances of a class that has multiple one-to-one bidirectional associations to the same class. Im using nhibernate-0.99.2.0.

Class A is mapped as:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
   namespace="Pncs.Lsm.DataModel" assembly="Pncs.Lsm.DataModel">

   <class name="A" table="LSM_A">
      
      <id name="Id" column="Id" type="Int32" unsaved-value="0">
         <generator class="identity"/>
      </id>
      
      <one-to-one name="B_1" class="B" cascade="all" />      
      <one-to-one name="B_2" class="B" cascade="all" />
      
   </class>
   
</hibernate-mapping>


Class B is mapped as:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
   namespace="Pncs.Lsm.DataModel" assembly="Pncs.Lsm.DataModel">

   <class name="B" table="LSM_B">
      
      <id name="Id" column="Id" type="Int32" unsaved-value="0">
         <generator class="identity"/>
      </id>
      
      <many-to-one name="A" class="A" column="A" unique="false"/>

   </class>
   
</hibernate-mapping>


The following code inserts correcly into the database:
Code:
         A a1 = new A();
         a1.B_1 = new B();
         a1.B_1.A = a1;
         a1.B_2 = new B();
         a1.B_2.A = a1;
         this.ds.Set(a1);

         A a2 = new A();
         a2.B_1 = new B();
         a2.B_1.A = a2;
         a2.B_2 = new B();
         a2.B_2.A = a2;
         this.ds.Set(a2);


Trying to then delete all these objects fails as follows:
Code:
this.ds.Clear(typeof(A));

{"DELETE statement conflicted with COLUMN REFERENCE constraint 'FKCFAF6AA2B5E4'. The conflict occurred in database 'XXX', table 'LSM_B', column 'A'.\r\nThe statement has been terminated." }



The SQL that hibernate is producing is as follows:
Code:
UPDATE LSM_B SET A = null WHERE Id = 2
DELETE FROM LSM_B WHERE Id = 1
DELETE FROM LSM_A WHERE Id = 1
DELETE FROM LSM_B WHERE Id = 2
DELETE FROM LSM_A WHERE Id = 2


The error makes sence and hibernate should be issuing another UPDATE LSM_B SET A = null WHERE Id = 1.

Should I be mapping these relationships in another way or is this a bug?

Thanks


Top
  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 5:03 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Are you sure you really want <one-to-one> and not <many-to-one> there? Two one-to-one relationships between two tables looks strange to me.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 05, 2005 4:27 am 
Thanks for your reply

Say class A above is a Customer and Class B is an Address.

The Customer class among other things has a MailingAddress and a ResidentialAddress property both of type Address.

How should this be mapped?


Top
  
 
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.