-->
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.  [ 4 posts ] 
Author Message
 Post subject: <one-to-one> help
PostPosted: Sat Oct 01, 2005 2:46 am 
Im getting confused here with a one to one mapping. I dont understand why I get a property-ref not found: AddressTypeID in class: AddressType when I can see in the c# code that the property AddressTypeID is definately in the AddressType class.

Setup:
Address table has 1-1 relationship to AddressType table.
f-key in address table to addressTypeID in addressType.

I have only declared the one-to-one relationship in the address.hbm.xml file. Heres what part of my Address mapping file looks like:

Code:
<property name="Postcode" column="postcode" />
<property name="Country" column="country" />
<one-to-one name="AddressTypeID" class = "LicenseManager.BusinessObjects.AddressType, LicenseManager" property-ref="AddressTypeID" />


With the classes the Address object stores a reference to an AddressType object and takes an AddressType in the constructor. The Address object also contains a Property which gets/sets an AddressType. There is no property in the Address class which would set the field it has for f-key integer value it should get from the AddressType class.

I hope someone can give a few clues. Thanks.


Top
  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 4:10 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
How does the mapping for the AddressType look? By the way, do you really have a 1-1 relationship? Can there only be one Address in the table for each AddressType?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 5:57 pm 
I understand that the db relationship is a one-to-many AddressType can be re-used for many Addresses. The reason I did not map this way in my xml is because another developer said the way the mapping works is based on the business relationship not the db relationship. I took that to mean from the class point of view the Address class has a single ref to a single AddressType.
For starters is this approach correct?
Anyhow heres the bulk of my AddressType xml file. The AddressType class has no ref to the Address class.

Code:
<class name="LicenseManager.BusinessObjects.AddressType, LicenseManager" table="AddressType">
   <id name="AddressTypeID" column="addressTypeID">
      <generator class="identity" />
   </id>
   <property name="Type" column="type" />
   <property name="IsActive" column="isActive" />
</class>


Gareth


Top
  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 6:11 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Hmm, do you have an AddressTypeID column in your Address table? If yes,
then you actually have a <many-to-one> there, not <one-to-one>. Property-ref is used when the relationship is made using some property that isn't a primary key, which is not your case, so just use plain <many-to-one name="AddressType" column="AddressTypeID" />.


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