-->
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.  [ 2 posts ] 
Author Message
 Post subject: Possible to dynamically create a named query?
PostPosted: Mon Dec 28, 2009 11:02 pm 
Newbie

Joined: Mon Dec 28, 2009 10:56 pm
Posts: 5
Hi guys,

As I understand it, in Hibernate I can:

  • create Queries, which are reuseable but not threadsafe
  • create NamedQueries, which are threadsafe but not creatable at runtime

Is there a third option? Any way to dynamically create, then cache and reuse, a Query without the performance hit of having to synchronize access to it?

Something like...

Code:
session.registerNamedQuery( "myQuery", "select a from Staff" )

I'd like to avoid the performance hit of recompiling commonly-executed queries, even when those queries aren't known in advance.

Regards,

Richard.


Top
 Profile  
 
 Post subject: Re: Possible to dynamically create a named query?
PostPosted: Fri Jan 15, 2010 12:59 pm 
Newbie

Joined: Thu Dec 24, 2009 10:14 am
Posts: 1
I'm not sure we're adressing the same problem but we may share information about generated named queries.
I'm looking for a way of generating basic (JPA) named queries such basic finders (findByXxx, findAll) in order to get the better performances I can with a maximum of industrialization and the less dynamic queries (in order to prevent from a slow one). A solution like the one you describe would be part of the answer I searched. Not all queries can be generated, but it would limit mistakes and make more acceptable for developpers to have and written named queries (instead of dynamic queries) for only the complex ones.

Here is what I found:

The project lombok could generate basic named queries, this is another approach using annotations and code generation at compile time.
* http://groups.google.com/group/project- ... 2226c081cb
* http://projectlombok.org

A guy over the hibernate forum seems using a traditionnal code generation approach with Hibernate Tools, but I didn't get a chance to try it for the moment.
viewtopic.php?f=9&t=962223&p=2315766&hilit=named+queries+generate#p2315766

Regards,

Araviski


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