Skip to content Skip to sidebar Skip to footer

Org.hibernate.hql.ast.querysyntaxexception: Unexpected Token

I'm working with Struts 2 and Hibernate and I'm getting this error : org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on near line 1, column 61 [SELECT s.codeOracle FR

Solution 1:

It's a HQL syntax error. HQL works with objects and have a different syntax rather than SQL. If you want to execute SQL query, then you should use

session.createSQLQuery(query)

the list() method returns List<Object[]>.

In the action class you have

privateList<Object[]> searchsiteList = newArrayList<Object[]>(); 

publicList<Object[]> getSearchsiteList() { return searchsiteList; }

but this code only binds searchsiteList in JSP. To bind other properties you should create a bean or use a map.

publicList<Map<String, Object>> convertToMapsList(List<Object[]> list){
  List<Map<String, Object>> res = newArrayList<>();
  for(Object[] arr : list){
    Map<String, Object> map = newHashMap<>();
    map.put("codeOracle", arr[0]);
    map.put("codeGSM", arr[1]);
    map.put("area", arr[2]);
    map.put("dateMiseOnAir", arr[3]);
    res.add(map);
  }
  return res;
}

and change

publicList<Map<String, Object>> getSearchsiteList() { returnconvertToMapsList(searchsiteList); }

Solution 2:

The create query returns a Query object. Try with below code.

Queryquery= session.createQuery(hql);
Listresults= query.list();

//join examples
query = session.createQuery("select e.name, a.city from Employee e "
           + "INNER JOIN e.address a");
List<Object[]> list = query.list();
for(Object[] arr : list){
      System.out.println(Arrays.toString(arr));
}

Your List is of type <Sites>. This may be causing issue.

Refer:

http://www.tutorialspoint.com/hibernate/hibernate_query_language.htm

http://www.journaldev.com/2954/hibernate-query-language-hql-example-tutorial

Post a Comment for "Org.hibernate.hql.ast.querysyntaxexception: Unexpected Token"