-->
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: Composite-id load
PostPosted: Sun Nov 18, 2007 3:45 am 
Newbie

Joined: Sun Nov 18, 2007 3:22 am
Posts: 8
Hi
I am new at NHibernate and I read the “NHibernate Quick Start Guide"

I have a table with two columns as Primery Key. i mapped it as a composite Id and i am trying to load a data of a specific ID.

this is my configuration file:
<class name="ItemData" table="PID_PerpetualInventory">
<composite-id>
<key-property name="ItemID" column="ProductID"/>
<key-property name="OrgID" column="OrgID"/>
</composite-id>
<property name="ItemQuantity" column="Quantity" type="double"/>
</class>

I off course succeded getting the data by using Criteria but i want to use a simple Load Or get.

I tried to create in my class a sub class the contains both the ItemID and OrgID but loading it returned an error.

at the next step i need is to get a list of ItemsData Id's and load the Quantity in the class.

Thx for the help.
tomer


Top
 Profile  
 
 Post subject: Re: Composite-id load
PostPosted: Sun Nov 18, 2007 12:43 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
By default NHibernate indexes the id by the actual object itself. Therefore you pass in an instance of the object you are trying to retrieve where you have set the primary key values. NHibernate will use that as the id and then load the object you are looking for.

Also keep in mind that whenever you are using composite ids you need to override Equals and GetHashCode. Equals must return true when the ids are the same (regardless of if the references are equal or not) and then GetHashCode must always return the same code for a given id. It is ok for two different ids to return the same code, so long as every time the same id is provided the same code is returned.

Hope that helps.


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.