Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error that unexpected token: ON near line 1, column 135

Tags:

hibernate

hql

I am new to hibernate and trying to run query in hibernate but i am getting the exception that

unexpected token: ON near line 1, column 135 [SELECT A.comp_id.appRefNo ....

Here is the code

StringBuffer query = new StringBuffer("SELECT A.comp_id.appRefNo, 
    A.comp_id.custId from ");

query.append(LosaCustContactZ.class.getName());

query.append(" A INNER JOIN " + LosaCust.class.getName() + " B 
    ON ( B.comp_id.appRefNo = A.comp_id.appRefNo AND " + 
    "B.comp_id.custId = A.comp_id.custId) INNER JOIN " + LosaApp.class.getName() + " C 
    ON " + "(B.comp_id.appRefNo = A.comp_id.appRefNo) ");

query.append("WHERE C.comp_id.appRefNo != ?" + " AND C.appDt >= ? AND 
    A.contactT = 'PHONE'" ); 

if (StringUtils.isNotEmpty(phoneNums)) {
    query.append(" AND A.contact IN(" + phoneNums + ")");
}

List<LosaCustContactZ> resultList = null;
try {
    resultList = getHibernateTemplate().find(query.toString(), 
           new Object[] { appRefNo, appDate });
} catch (Exception e) {
    String message = e.getMessage();
System.out.println();
}
return resultList;

what i am doing wrong ?

Thanks

like image 666
Basit Avatar asked Dec 20 '22 08:12

Basit


2 Answers

Many constructs from SQL cannot moved one-to-one to the HQL. In HQL keyword WITH is used instead of ON, when joining with specific condition. This construct is specific to Hibernate and is not expected to work with other JPA providers.

Chapter about HQL and especially 16.3 Associations and Joins in Hibernate Core Reference Manual are worth of reading.

like image 77
Mikko Maunu Avatar answered Feb 16 '23 04:02

Mikko Maunu


Seems like there is a mapping association missed in your hbm.xml.

Please refer this.

No defined association in hbm.xml file

like image 40
Suresh Atta Avatar answered Feb 16 '23 03:02

Suresh Atta