-->
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.  [ 1 post ] 
Author Message
 Post subject: CreateCriteria on One-To-Many relation to set max results
PostPosted: Thu Jul 02, 2009 7:44 am 
Newbie

Joined: Thu Feb 07, 2008 6:48 am
Posts: 14
NHibernate version: NHibernate-2.0.1.GA
On SQLServer 2005

Hello,

I have a very strange problem here. The situation is as follows:

I have an Customer class and an Address class.
A Customer can have 1 or more Addresses.

So in the Customer domain class I have an ISet of Addresses. <set><one-to-many>...</one-to-many></set>
In the Address class I have a reference back to te Customer class. <many-to-one/>

I have 2 datagrids:

Datagrid 1: The customers.
Datagrid 2: The Addresses of a selected Customer.

This all works fine. But, i would like to narrow down the number of results in both grids. So I would like to use SetMaxResults.
This also works fine for my customers. I do this like:

ICriteria criteria = NHibernateSession.CreateCriteria(persistentType); (persistentType = Customer)
criteria.SetFirstResult(0);
criteria.SetMaxResults(500);

This narrows down the customers to max 500 rows.

Now I come to the problem part:

I would like to do the same for the addresses. When a user clicks on a customer
NHibernate automatically goes querying the related addresses. But I would like to see max 500 addresses per customer. I do this like:

ICriteria criteria = NHibernateSession.CreateCriteria(persistentType);
criteria.SetFirstResult(0);
criteria.SetMaxResults(500);
ICriteria addressCriteria = criteria.CreateCriteria("Address", JoinType.None);
addressCriteria.SetFirstResult(firstrow);
addressCriteria.SetMaxResults(pagesize);

But this doesn't do anything :(
I do not want to change the JoinType because this gives me duplicate entries in the Customer datagrid.

Is there anyone out there that can help me with this problem? Is there maybe another solution
for setting the max results on a many-to-one select?

I also wanted to add a restriction to the Address via:
criteria.Add(...); but this only works when the JoinType != None

Thanks in advance to you all!!!

Marten


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.