java.lang.ClassCastException: org.hibernate.internal.QueryImpl cannot be cast to com.models.User
<p>I have a user table structured this way</p>

<pre><code>id    name     email
1     cc       cc@yahoo.com
2     rr       rr@yahoo.com
3     cc       cc@yahoo.com
</code></pre>

<p>I am writing a query to save a log when ever it finds an email matching any of the row with the below hql</p>

<pre><code>String hql = "FROM User c WHERE c.email = :email order by c.id";
        return (User) _sessionFactory.getCurrentSession().createQuery(hql).setParameter("email", email);
</code></pre>

<p>When I run my code I get this error</p>

<pre><code>java.lang.ClassCastException: org.hibernate.internal.QueryImpl cannot be cast to com.models.User
    at com.models.UserDao.getByEmail(UserDao.java:62)
</code></pre>