-->
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.  [ 7 posts ] 
Author Message
 Post subject: Is it possible to translate Hibernate Criteria to HQL
PostPosted: Fri Dec 22, 2006 6:07 pm 
Newbie

Joined: Mon Nov 06, 2006 12:39 pm
Posts: 5
I know for Query you can get the underlying HQL, but it looks like Criteria and Query are completely different, they dont interact with each other, i am wondering if it is possible to get the underlying HQL/SQL of a Criteria.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 23, 2006 8:34 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I guess yes. I seem to remember that hibernate in fact translates Criteria queries into HQL, then translated to SQL. But I didn't look how to retrieve this HQL query if I'm right.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 24, 2006 3:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it is a very stubborn folklore that criteria translates to HQL. Criteria goes directly to SQL, but there is no direct public api to get it programmatically.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 24, 2006 8:01 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
max wrote:
it is a very stubborn folklore that criteria translates to HQL. Criteria goes directly to SQL, but there is no direct public api to get it programmatically.

Perfect :-). Now I know it for good. Thanks for reestablishing the truth max :).

Well, at least, it did seem quite logical for me : I thought it'd have been a way of reusing the already done work on HQL to implement Criteria in addition.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 24, 2006 11:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
translating twice isn't very efficient ;)

anyhow there is actually work being done to share some of the translation but that is more about sharing the underlying code than the actual language.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 24, 2006 11:23 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
max wrote:
translating twice isn't very efficient ;)

Totally agreed :). But programming is often finding the right balance between performance and maintainability, which is also often opposites.
max wrote:
anyhow there is actually work being done to share some of the translation but that is more about sharing the underlying code than the actual language.

Perfect :).

Cheers

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: Re: Is it possible to translate Hibernate Criteria to HQL
PostPosted: Sat Jul 10, 2010 4:38 pm 
Newbie

Joined: Sat Jul 10, 2010 4:34 pm
Posts: 1
I have modified the Hibernate Criteria API to generate JPQL queries by trying to preserve the interface mostly similar. Name of my project is Criteria2JPQL at:

https://sourceforge.net/projects/criteria2jpql/

Since this translation is a simple in-memory operation that generates a standard JPQL query, there is not a considerable cost of time. On the other hand, the idea of this project has originated from the poor performing native sql queries of Hibernate Critera including lots of unnecessary joins. We have experienced using Criteria2JPQL in our project at my company and observed those unnecessary joins disappeared.


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