title: java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.FromReferenceNode
body: <p>I am trying to execute a select statement in JPA which is throwing me the above error. The code is:</p>
  
  <pre><code>TypedQuery&lt;ListPersonsObj&gt; typedQuery = null;
  String query = "";
  List&lt;ListPersonsObj&gt; list = null;
  if (some condition) {
     query = "SELECT NEW in.healthelife.DGS.dao.ListPersonsObj"
                      + "(c.personId, c.givenName, c.middleName, c.address1, "
                      + "c.address2, c.dateOfBirth, "
                      + "c.phoneNumber, c.email) FROM Patients c";
     typedQuery = EntityManagerUtil.getEntityManager()
                     .createQuery(query, ListPersonsObj.class);
     list = typedQuery.getResultList();
  }
  </code></pre>
  
  <p>The ListPersonsObj class:</p>
  
  <pre><code>public class ListPersonsObj {
  
     private Long personId;
     private String givenName;
     private String middleName;
     private String address1;
     private String address2;
     private String dateOfBirth;
     private String phoneNumber;
     private String email;
  
     public ListPersonsObj() {
     }
  
     public ListPersonsObj(Long personId, String givenName, String middleName,
           String address1, String address2,
           String dateOfBirth, String phoneNumber, String email) {
        this.personId = personId;
        this.givenName = givenName;
        this.middleName = middleName;
        this.address1 = address1;
        this.address2 = address2;
        this.dateOfBirth = dateOfBirth;
        this.phoneNumber = phoneNumber;
        this.email = email;
     }
  
     public ListPersonsObj(ListPersonsObj list) {
        try {
           BeanUtils.copyProperties(this, list);
        } catch (IllegalAccessException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
        } catch (InvocationTargetException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
        }
     }
     // .. getters &amp; setters 
  }
  </code></pre>
  
  <p>Exception caught</p>
  
  <blockquote>
    <p>java.lang.ClassCastException:
    org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to
    org.hibernate.hql.internal.ast.tree.FromReferenceNode</p>
  </blockquote>
  
  <p>Can anyone please shed some light on this. </p>