I am trying to do a simple select count statement from a method which works on my other part of program but here it gives me error.
public Long validateSub(String source, String tbl){
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Query q = session.createQuery("SELECT count(s) from SlaveSubscribers s where s.SOURCENAME = :sourcename AND s.TBL = :tbl");
q.setParameter("sourcename", source);
q.setParameter("tbl", tbl);
Long result = (Long) q.list().get(0);
session.getTransaction().commit();
return result;
}
The Error message:
Exception in thread "Thread-3" org.hibernate.QueryException: could not resolve property: SOURCENAME of: com.datadistributor.main.SlaveSubscribers [SELECT count(s) from com.datadistributor.main.SlaveSubscribers s where s.SOURCENAME = :sourcename AND s.TBL = :tbl]
I have no idea why this does not work
You do not have persistent attribute (field) SOURCENAME in SlaveSubscribers entity. Most likely SOURCENAME is name of the database column. In HQL you need to use name of the field (case sensitive).