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
|