-->
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: SQL error
PostPosted: Thu Dec 07, 2006 2:14 pm 
Newbie

Joined: Thu Dec 07, 2006 2:05 pm
Posts: 3
i got the following error :

Caused by: java.sql.SQLException: Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ASC limit 25' at line 1"




here is my java code :
Query q = s.createQuery(
"select distinct nsc " +
"from NodeStateChange as nsc " +
"where nsc.node.category in (:categories) and " +
" nsc.node.name like :nname AND " +
" nsc.state = :nstate and " +
" (nsc.end - nsc.begin) > :ndtime " +
"order by "+ config.getSortColumn()+" "+ config.getSortDirection());

q.setParameterList("categories", allowedCategories);
q.setString("nname", "%" + config.getQueryText() + "%");
q.setParameter("nstate", NodeState.UNREACHABLE, Hibernate.custom(NodeStateUserType.class));
q.setInteger("ndtime", config.getMinDowntime());



config.getSortColumn() will return one of these :
nsc.node.name
nsc.begin
nsc.en

it doesnt seem to accept the config.getSortColumn, i even tried replacing it with a variable and then using q.setParameter, this does not work either...i dont understand cause why it accepts the config.getSortDirection properly but not the other one...cause i tested it using

" order by nsc.node.name " + config.getSortDirection() ; "

and this works! ...could somebody please advice


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 2:27 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
In your hibernate.cfg.xml file turn on the show_sql flag. Copy the SQL string from the console and run it against your database manually.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 3:08 pm 
Newbie

Joined: Thu Dec 07, 2006 2:05 pm
Posts: 3
hey i tried doing that already.... that does not help in anyway....it gives me the same error , i just want to how to get "Config.getsortColumn" part of the query to work properly.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 4:12 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
if hardcoding "nsc.node.name" into the hql query works and the method call makes the sql invalid, I must venture to guess that your method is not returning what it should be returning

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 4:27 pm 
Newbie

Joined: Thu Dec 07, 2006 2:05 pm
Posts: 3
yes i thought the same thing so i did a System.out.println(config.getsortcolumn) and it give me nsc.node.name!!!

i dont know if there are maybe some special characters that are getting added or what...i am completely bewildered by this....and no one in my office is able to figure it out


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.