-->
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: one-to-one with property-ref
PostPosted: Mon Nov 07, 2005 4:20 pm 
Beginner
Beginner

Joined: Thu May 26, 2005 1:00 pm
Posts: 29
Given the documentation on one-to-one mappings, I suspect this mapping to express the subsequent relationship:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-access="field">
  <class name="SpringAir.Parts.PartOut, SpringAir.Objects" table="PartOut">
    <id name="partOutId" type="Int32" column="PartOutId" unsaved-value="-1">
       <generator class="hilo"><!--... blah, blah ... --></generator>
    </id>
    <many-to-one name="partIn" column="PartInId" cascade="all" unique="true" />
  </class>

  <class name="SpringAir.Parts.PartIn, SpringAir.Objects" table="PartIn">
    <id name="partInId" type="Int32" column="PartInId" unsaved-value="-1">
       <generator class="hilo"><!--... blah, blah ... --></generator>
    </id>
    <one-to-one name="partOut" property-ref="partIn" cascade="none" />
  </class>
</hibernate-mapping>

Code:
Table PartIn:
-------------------
| PartInId (int)  |
-------------------
Table PartOut:
--------------------------------------
| PartOutId (int)  |  PartInId (int) |
--------------------------------------

Code:
public class PartOut {
  int partOutId;
  PartIn partIn;
}
public class PartIn {
  int partInId;
  PartOut partOut;
}

According to the docs, this should correspond to a bidirectional one-to-one relationship with a unique foreign key.

However, the property-ref on the partIn side is loading the PartOut where PartOut.PartOutId=PartIn.PartInId, not PartOut.PartInId=PartIn.PartInId like I expected. Can anyone see anything wrong with the above?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 6:05 am 
Beginner
Beginner

Joined: Mon Oct 03, 2005 4:59 am
Posts: 26
Location: Cambridge, UK
Well, I have no idea if this is something that could cause your problem, but I don't see class="whatever" in your many-to-one and one-to-one tags. The docs (http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-onetoone) seem to imply that there should be a class tag there.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 12:46 pm 
Beginner
Beginner

Joined: Thu May 26, 2005 1:00 pm
Posts: 29
The docs specify that the "class" attribute is optional, since NHibernate can infer the type from the object's field. I tried including it on both sides anyway, and I haven't run into the problem anymore, so perhaps it seems to be fixed.

I just tried removing it from both sides, and can reproduce the problem. I then added it just to the one-to-one side (PartIn->PartOut), and it's fixed again. This seems to be a bug since the behaviour is at odds with the docs.


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.