-->
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.  [ 29 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Is it possible to create a "killer query" in Hiber
PostPosted: Fri Jul 29, 2005 7:02 am 
Newbie

Joined: Tue Sep 28, 2004 7:20 pm
Posts: 9
Thought I'd ask here before I go browsing the code and running experiments.

Is it possible to create a "killer query" in Hibernate? That is could I do a find that causes so many objects to be instantiated that the system runs out of memory.

And if so, how are people dealing with this? Explicit row limits in all queries?


Top
 Profile  
 
 Post subject: Re: Is it possible to create a "killer query" in H
PostPosted: Fri Jul 29, 2005 7:26 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
jchyip wrote:
Thought I'd ask here before I go browsing the code and running experiments.

Is it possible to create a "killer query" in Hibernate? That is could I do a find that causes so many objects to be instantiated that the system runs out of memory.

And if so, how are people dealing with this? Explicit row limits in all queries?


I think people generally deal with this problem by applying good design a programming practices to solving real business problems and not by looking for how to break something.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Real business problems?
PostPosted: Fri Jul 29, 2005 8:08 am 
Newbie

Joined: Tue Sep 28, 2004 7:20 pm
Posts: 9
The "real business problem" would be the ability for a user to take down the entire application by initiating a query that causes the application to run out of memory.

A previous home-grown O/R mapping framework we used, limited the number of objects that were allowed to be created in the IdentityMap to prevent this problem. We've now migrated to Hibernate. Is there something similar in place? And if not, how are people addressing this risk?

We've including explicit result limits in the cases that we considered likely to be a problem but it would be preferable to have a catch all safety net.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 8:17 am 
Beginner
Beginner

Joined: Wed May 04, 2005 5:17 am
Posts: 40
I would be concerned about allowing users the ability to execute arbitrary queries.

But yes, the typical guard would be to set min and max results.

Do you have a use case where you want to return *every* row or are you just hypotheticaling ;)


Top
 Profile  
 
 Post subject: Really just a saftey net for programming mistakes
PostPosted: Fri Jul 29, 2005 9:25 am 
Newbie

Joined: Tue Sep 28, 2004 7:20 pm
Posts: 9
Users cannot execute arbitrary queries but I'd consider it possible that some existing or future development misses out on a potential result set blow-out. Having some mechanism to limit the number of objects from query results is
as I said, more a safety net.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 9:38 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
So you trade off potentially incorrect query results (which information is skipped?) for not having to see when developers did bad things?


Top
 Profile  
 
 Post subject: Fail operation vs crash application
PostPosted: Fri Jul 29, 2005 9:45 am 
Newbie

Joined: Tue Sep 28, 2004 7:20 pm
Posts: 9
Quote:
So you trade off potentially incorrect query results (which information is skipped?) for not having to see when developers did bad things?


Previous framework would throw an exception that would fail the operation, that is, no query results. Obviously preferable that nothing that reached production would be able to trigger this failure, but a failed operation is better than a crashed application.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 9:47 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
In testing, whats the difference?


Top
 Profile  
 
 Post subject: Can't assume testing will catch everything
PostPosted: Fri Jul 29, 2005 9:59 am 
Newbie

Joined: Tue Sep 28, 2004 7:20 pm
Posts: 9
christian wrote:
In testing, whats the difference?


By this, I think you're suggesting that this doesn't really matter in testing. I'd actually think it would be nicer from a development speed point of view that even the test environment didn't die because of a bad query. I'd rather a nice exception message.

But, I'm assuming that I can't rely on testing to catch everything.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 10:03 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Well, I guess it's really easy to limit the entries in a persistence context in Hibernate and throw some exception if that limit is reached. I just don't see the value, as the number of entries has not much influence on the memory consumed.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 10:28 am 
Newbie

Joined: Wed Apr 14, 2004 4:58 am
Posts: 6
To avoid out-of-memory problems, you can use query iterating lazy-fetching and discard used objects from session.

E.g. if you want to output a lot of data (e.g. every object in hibernate), you can run:

for (Iterator i=session.createQuery("from Object").iterate();i.hasNext();)
{
Object o=i.next();
outputObject(o);
session.evict(o);
}

This instaciates the results object by object and session.evict() removed the object from the session cache when it's no more used.

Michael.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 12:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
jchyip if you are a non-native english speaker, you need to learn the meaning of "unhelpful". It is not the negation of "solves my immediate problem right now"!

http://dictionary.reference.com/search?q=unhelpful

If you are a native English speaker, then what you just did (rating Christian's comments down) is close to what I would consider a bannable offence.

Don't do that again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 12:43 pm 
Beginner
Beginner

Joined: Wed May 04, 2005 5:17 am
Posts: 40
Gavin; whats the quickest way to loose customers? Introduce a rating system and then mention "banning" if they don't rate the way you want ;)

Really. Think about it ;)

I am an English speaker and if something doesn't directly lead me to a solution, then it isn't helpful. Sure, it may not have been unhelpful, but it sure wasn't helpful ;)

Maybe you should change the ratings to "appreciated" and "unappreciated". You guys started this can of worms ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 12:46 pm 
Beginner
Beginner

Joined: Wed May 04, 2005 5:17 am
Posts: 40
And for what its worth, I agree he shouldn't have marked it as unhelpful, just not sure anyone from Hibernate team should be saying so ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 1:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yatesco wrote:
Gavin; whats the quickest way to loose customers?


Apparently you have a very, very different definition of the word "customer" to the one I work from. :) Our customers have a special support portal where all questions are guaranteed to be answered by the Hibernate team in a timely manner. The forum is specifically for non-customers.

The point of the credit system is to encourage people to act as a "community", meaning that people will try to help, even when they are not absolutely sure of the answer. If they get rated down for doing this (and I've been noticing a few instances of this already), then people will be discouraged from trying to help.

Calling someone who is trying to help you "not helpful" is extremely rude behavior in my view, and if I see people doing this, I will treat them accordingly.

Understand that the main value of the credit system is to encourage and reward question answerers, not question askers :-)

Quote:
Maybe you should change the ratings to "appreciated" and "unappreciated".


I'm trying to get this issue sorted out with Christian. At the very least, We need better documentation of what the ratings are intended to mean. I must admit that right now I'm even fuzzy on what is the actual effect of a "not helpful" rating.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 29 posts ]  Go to page 1, 2  Next

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.