One of my DAO methods contains the following method:
@Override
public boolean isAvailable(String code) {
Criteria criteria = getSession().createCriteria(MyEntity.class);
cr.add(Restrictions.eq("code", code).ignoreCase());
cr.setProjection(Projections.rowCount());
Long rowCount = (Long) cr.uniqueResult();
return (rowCount > 0) ? true : false;
}
On the last line the following exception is thrown:
org.hibernate.exception.DataException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2452)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2192)
at org.hibernate.loader.Loader.list(Loader.java:2187)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1706)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:369)
The code
is primary key in this table. Hibernate is generating its select command in console. When I am checking this select command in SQL console in my database it returns correct values. So what am I doing wrong?