-->
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.  [ 5 posts ] 
Author Message
 Post subject: Very puzzling behaviour in NHibernate HQL.
PostPosted: Thu Aug 04, 2005 12:53 pm 
Newbie

Joined: Sat Jul 09, 2005 1:17 pm
Posts: 17
I've created an HQL statement to get a specific class and some of its one to many amd many to one properties. I also have filters in my "where" clause to only get some of the elements in its one to many collections.

I discovered that NHibernate disregrads these filters and gives me all the elements in the collections!!

My NHibernate session persists for the entire life of the asp.net session. Perhaps NHibernate is getting the values from the cache without realizing that I am doing a filter in my HQL and do not want all the values from the cache.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 3:39 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This is by design, NHibernate won't load a persistent collection with less elements than it truly has. Try using ISession.CreateFilter instead.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 2:22 pm 
Newbie

Joined: Sat Jul 09, 2005 1:17 pm
Posts: 17
This is not good design. HQL should always return what you expect it to, wether it has a where clause or not. I shouldn't have to use a different API if I want to filter.

Suppose I start out with an HQL statement that does not have filters and some time later I need to add a filter to it. Now I have to rewrite my code to use a different API. This is not good design.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 2:28 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Well, I myself believe the design is right, useful to prevent strange bugs later. If you have a Customer, then Customer.Orders are all Customer's orders, no matter where you got it from and what query you used. If you only want some of the orders, you filter the collection.

Another reason why we won't change it is that Hibernate does things this way.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 3:04 pm 
Contributor
Contributor

Joined: Thu Jun 23, 2005 1:08 pm
Posts: 32
Location: Baltimore, MD
Think of objects, not database rows.

If you have "FROM Customer", you are selecting a customer, the whole customer. Even if it is "customers with an order over $300" you are going to get all the orders when you reference customer.Orders.

And like sergey said, Hibernate does it, so NHibernate does it.

you could do: "SELECT c, o FROM Customer c INNER JOIN c.Orders o WHERE o.Amount > $300" and get back a list of 2 element arrays, a customer and a matching order. Not sure if this is what you want.


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