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: Querying a table with primary keys set to multiple columns
PostPosted: Wed Feb 27, 2008 4:31 pm 
Newbie

Joined: Wed Feb 27, 2008 4:20 pm
Posts: 3
I have a datatable with 3 columns (hostid, name, value). The primary key for uniqueness in it is a combonation of hostid and name, since there are many non-unique hostid with unique name. Whenever I make a call to nhibernate to retrieve a list of all elements with a certain hostid, it returns a list of only the first element in the database that matches the criteria multiple times. Does anyone know how to fix this? I've included a part of the mapping file and source code where i make the calls.

Source:
ISessionFactory factory = getSessionFactory();
ISession session = factory.OpenSession();

//Create the search criteria.
ICriteria crit = session.CreateCriteria(typeof(WilHostProperty));
crit.Add(Expression.Eq("HostID", host.ID));
crit.

IList temp = crit.List();

foreach (WilHostProperty hostProp in crit.List())
{
try
{
host.Properties.Add(hostProp.Name, hostProp);
}
catch (Exception) { } //Occurs if item exists already
}



The mapping file:

<class name="WilHostProperty" table="WIL_HOST_PROPERTIES">
<id name="HostID" column="WIL_HOST_ID" type="Int32">
<generator class="native"/>
</id>
<property name="Name" column="NAME" type="String"/>
<property name="Value" column="VALUE" type="String"/>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 27, 2008 4:48 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Sounds like you want to use a composite identifier and consists of your hostid and name fields.

There's information in the documentation about composite identifiers here:

http://www.hibernate.org/hib_docs/nhibe ... ompositeid

Cheers,

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


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.