-->
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.  [ 6 posts ] 
Author Message
 Post subject: Query.iterate() and ResultSet/Statement closure...
PostPosted: Wed May 05, 2010 9:02 am 
Newbie

Joined: Wed May 05, 2010 8:39 am
Posts: 7
I'm not sure, but using method Query.iterate() I think related ResultSet and Statement are
not closed if you don't traverse the Iterator till the end.

I would like to avoid problems in this type of scenario:

I have a CustomerPersistenceAdapter with a getWonderfulCustomers returning
and Iterator<Customer>.
Another developer needs only the first wonderful Customer and looking
at an already developed api he writes:

Code:
    ...
    Iterator<Customer> it = persistenceAdapter.getWonderfulCustomers();
    return (it.hasNext()) ? it.next() : null;
    ...


If the Iterator<Customer> returned by getWonderfulCustomers need to traverse
more than one Customer, are the ResultSet and Statement closed?
Can this create problems or there are other subsystems to clean or notify this
situation?

Thanks in advance
Bye


Top
 Profile  
 
 Post subject: Re: Query.iterate() and ResultSet/Statement closure...
PostPosted: Wed May 05, 2010 10:36 am 
Beginner
Beginner

Joined: Fri Aug 24, 2007 9:47 am
Posts: 21
Isn't there a size method on PersistenceAdapter who you will let to check ?

_________________
recherche-programmeur.fr


Top
 Profile  
 
 Post subject: Re: Query.iterate() and ResultSet/Statement closure...
PostPosted: Wed May 05, 2010 12:33 pm 
Newbie

Joined: Wed May 05, 2010 8:39 am
Posts: 7
Hi iometrine and thanks. I could add a size method, but this isn't the purpose of my question.

I'm wondering whether I have to recommend CustomerPersistenceAdapter users to traverse returned Iterator<Customer> till the end (adding method documentation for example).

I would like to avoid memory leaks for ResultSet/Statement leaved in memory.

Probably only an Hibernate developer can answer this question...


Top
 Profile  
 
 Post subject: Re: Query.iterate() and ResultSet/Statement closure...
PostPosted: Tue May 11, 2010 5:06 am 
Newbie

Joined: Wed May 05, 2010 8:39 am
Posts: 7
Hi, any answer?


Top
 Profile  
 
 Post subject: Re: Query.iterate() and ResultSet/Statement closure...
PostPosted: Tue May 11, 2010 6:26 am 
Newbie

Joined: Wed May 05, 2010 8:39 am
Posts: 7
Found an answer, tell me if it's good...

It's better to use .scroll() method and return a ScrollableResults.
I have seen that this class has a close method with api doc saying "Release resources immediately".

What do you think?


Top
 Profile  
 
 Post subject: Re: Query.iterate() and ResultSet/Statement closure...
PostPosted: Wed May 19, 2010 10:04 am 
Newbie

Joined: Wed May 05, 2010 8:39 am
Posts: 7
No answers means "ops there is a problem?"


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