-->
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: is there a way to parse HQL?
PostPosted: Fri May 25, 2007 4:24 pm 
Newbie

Joined: Tue May 15, 2007 5:02 pm
Posts: 12
is there a way to parse HQL at runtime and manipulate where clause?

thanks in advance...


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 5:33 pm 
Beginner
Beginner

Joined: Fri Nov 03, 2006 6:15 am
Posts: 21
HQL is just a query that you execute and is defined as a string...so yes you can change a HQL.

if you have

Code:
Query q = sess.createQuery(query);


then the query object represents a string and you can manipulate it
as you want.

You have the following possibilities:

Code:
query = "Select FROM test where name='"+testVariable+"'";


or you use keywords:

Code:
query = "Select FROM test where name =:name";


and set the value after

Code:
q.setString("name", "yourvalue");


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 5:41 pm 
Newbie

Joined: Tue May 15, 2007 5:02 pm
Posts: 12
yeah... but I need it for general purpose. For complex queries it is difficult to manuplate manually.. I am looking for some API that enables you to modify where clause...


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 5:45 pm 
Beginner
Beginner

Joined: Fri Nov 03, 2006 6:15 am
Posts: 21
hmmm i dont get you....your criterias can be as complex as you want...at the end you have different possibilities...

using the criteria API and not HQL

using HQL

using native SQL...

But in all the cases you need to gather the criterias and add them in the first case or change the HQL/SQL-String...

No API will help you specify your problem ;-) With all the 3 listed possibilites your able to change the WHERE clause at runtime


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 5:54 pm 
Newbie

Joined: Tue May 15, 2007 5:02 pm
Posts: 12
I already have Named query defined. I need to modify it at runtime. And this is general and applied for all the queries in application.

There is no way to create Criteria from Named query.


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.