-->
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: Query creation time and Session association
PostPosted: Wed Jan 14, 2004 6:29 am 
Newbie

Joined: Mon Sep 15, 2003 8:06 am
Posts: 8
Hello

First of all thank you all for the work done.
I am currently testing a newly developed application based on stateless
EJB sessions executing many HQL queries. One of the bottlenecks in
the application is the memory consumed by HQL query instanciations.
Given a HQL string, why hibernate must re-parse and regenerate
a QueryImpl each time a session.createQuery is achieved ? Given that
all sessions are obtained from the same SessionFactory, this should result
in equivalent QueryImpl objects ? So could it be possible to extend the
caching strategy of Hibernate so that a query is fully compiled only the
first time a new HQL is encountered, for a given SessionFactory ?
Afterwards, an instance of such a Query could be internally cached and clone()d (or something like this) each time createQuery is called with the same HQL ?

Am I totally wrong ?

Thank you in advance for any advice, and good luck for hibernate 2.2... ;-)

sincerely yours

Emmanuel Ligne


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 6:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You are mistaken. Hibernate caches compiled HQL queries.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 6:53 am 
Newbie

Joined: Mon Sep 15, 2003 8:06 am
Posts: 8
Is this Query cache by Session or by SessionFactory ?
To be more accurate : given 2 sessions from the same sessionfactory,
if I call createQuery(myHQL) on one session, this will create a new
QueryImpl. If I recall it on the same session, the query cache should
return me the same QueryImpl instance. Nice.
Now if I call createQuery(myHQL) (the same HQL) on the other session,
does hibernate gives me the previously instanciated query or does it
compile a new one ? Personally I vote for the second choice, while
I would have liked the first one (as both sessions are from the same
sessionfactory). Optionally for thread safety, return a clone of the already
instanciated query.

Am I wrong ?

And thank you for your quick answer Gavin (as usual...).

Sincerely yours

Emmanuel Ligne


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 5:53 am 
Newbie

Joined: Mon Sep 15, 2003 8:06 am
Posts: 8
Hello again

I just looked at the SessionImpl code (in hibernate 2.1.1) and it seems
like query caching is only enabled when executing HQL via
session.find or session.iterate.
When calling createQuery on a session, a new QueryImpl instance
is created, resulting in a new HQL parsing and so. Features of Query
such as max-result count and parameterList (ie usage of IN in hql)
are a must-have for my app, and they don't seem to be available in
the simpler, direct call to session.iterate/find.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 6:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
look again, you have misunderstood the code - all compiled HQL queries are cached in the SessionFactory


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.