unexpected token

Posted on 2008-11-11
Last Modified: 2012-05-05
I would like to retrieve count of the rows in ScanPT table.
I wrote this query in Hibernate console and got the result 2.

When i use it in my Java code it throws me ERROR org.hibernate.hql.PARSER - line 1:182: unexpected token: q
Can you tell me what iam doing wrong ?

public int checkForPT(long id) throws Exception{
      String sql = "select count(pt) from ScanPT as pt where in " +
                         "(select      from Queue as q      inner join q.scanCompany as tasks"+
                         "where = ? )";
      List  pnrCount = getHibernateTemplate().find(sql,id);      
      int result = pnrCount.size();      
      return result;
Question by:Siddhardh
    LVL 44

    Accepted Solution

    Hello Siddhardh,

    You concatenate the bits so there is no space between tasks"+"where

    public int checkForPT(long id) throws Exception{
          String sql = "select count(pt) from ScanPT as pt where in " +
                             "(select      from Queue as q      inner join q.scanCompany as tasks "+
                             "where = ? )";
          List  pnrCount = getHibernateTemplate().find(sql,id);      
          int result = pnrCount.size();      
          return result;

    Should solve it.



    Author Closing Comment

    Thanks Much Tim

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now