I am getting an error when i am trying to display few contents of a table using named query in hibernate. I have tried looking for answers, with no success. The code is listed below.
<sql-query name="ActiveCustomers">
<return alias="cts" class="Customer"/>
SELECT
cts.cid AS {cts.cid},
cts.cname AS {cts.cname},
cts.email AS {cts.email},
cts.status {cts.status}
FROM Customers cts
WHERE cts.status=:st
</sql-query>
From the client side I am invoking it as shown below:
SessionFactory sf=CHibernateUtil.getSessionFactory();
Session session=sf.openSession();
tx=session.beginTransaction();
list=session.getNamedQuery("ActiveCustomers").setString("st","Active").list();
for(Customer c:list){
System.out.println(c);
}
tx.commit();
session.close();
But I am getting this error:
Hibernate:
SELECT
cts.cid AS cid0_,
cts.cname AS cname0_0_,
cts.email AS email0_0_,
cts.status status0_0_
FROM Customers cts
WHERE cts.status=?
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
.
.
Caused by: java.sql.SQLException: Column 'city0_0_' not found.
But If i add all the columns of the table then it works. But that's not my requirement. My requirement is to display only cid,cname,email and status.