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

跟風遠走 提交于 2019-12-03 16:33:12

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

Please refer this.

No defined association in hbm.xml file

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.

Try the following code after correcting tables/columns names:

public static List<Object[]> getTopRequests(int start, int end)
        throws Exception {
    List<Object[]> list = null;
    Session session = null;

    try {
        session = HibernateUtil.openSession();

        session.beginTransaction();

        Query q = session.createQuery("SELECT "
                + " tr.id as id, "
                + // Column 0
                " tr.amount as amount,"
                + // Column 1
                " tcp.phoneNum as phoneNum, "
                + // Column 2
                " trs.faTitle as faTitle, "
                + // Column 3
                " tr.createDate as createDate "
                + // Column 4
                " FROM TopRequest as tr " + " , TopCellPhone as tcp "
                + ", TopRequestState as trs  "
                + " WHERE tcp.tcpId = tr.tcpId "
                + " AND tr.trsId = trs.trsId  "
                + " ORDER BY tr.updateDate DESC");

        q.setFirstResult(start);
        q.setMaxResults(end - start);
        list = (List<Object[]>) q.list();

        session.getTransaction().commit();

    } catch (Exception e) {
        _log.error(e.getMessage(), e);
    } finally {
        HibernateUtil.closeSession(session);
        return list;
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!