-->
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: Identify if HQL or native SQL query
PostPosted: Thu Dec 23, 2010 2:23 am 
Newbie

Joined: Fri Dec 17, 2010 3:12 am
Posts: 8
Hi,

Is there any way by which I can identify, whether the named query I get is an HQLQuery or a native SQL query?

Regards,
Sandeep


Top
 Profile  
 
 Post subject: Re: Identify if HQL or native SQL query
PostPosted: Thu Dec 23, 2010 3:46 am 
Newbie

Joined: Fri Dec 17, 2010 3:12 am
Posts: 8
My requirements is -
if i have an <query>, i use filter..
and since <sql-query> doesn't support filter, I have to append an AND clause to my SQL query..

so based on whether it is a HQL or SQL query, i have to make changes but am unable identify the type..

Any suggestions?


Top
 Profile  
 
 Post subject: Re: Identify if HQL or native SQL query
PostPosted: Thu Dec 23, 2010 5:53 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
Any suggestions?

You shouldn't add anything to a native SQL, filters are not supported because that breaks so easily.
Better to declare an additional query having the filter already.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Identify if HQL or native SQL query
PostPosted: Thu Dec 23, 2010 5:55 am 
Newbie

Joined: Fri Dec 17, 2010 3:12 am
Posts: 8
Have solved it as follows -

query = session.getNamedQuery(queryId);

if(query.getClass().getSimpleName().equals("SQLQueryImpl")){
//process for SQL
} else
//process for HQL


Top
 Profile  
 
 Post subject: Re: Identify if HQL or native SQL query
PostPosted: Thu Dec 23, 2010 5:57 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
still, I don't think you should change a NamedQuery after it's defined.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Identify if HQL or native SQL query
PostPosted: Fri Dec 24, 2010 7:18 am 
Newbie

Joined: Fri Dec 17, 2010 3:12 am
Posts: 8
hi sanne,

Thanks for the response. I understand it's not advisable to edit your named query. :(
But my requirement is a bit strange, which is described here -

https://forum.hibernate.org/viewtopic.php?f=1&t=1008837


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.