Archive for April, 2016

Get or count(*) (row count) from hibernate criterion

public Integer getActiveAlertCount(Company company){ Alert alert = new Alert(); Integer count = 0; try { Session session = getSession(); Criteria c = session.createCriteria(MyClass.class,”myalias”); c.add(Restrictions.eq(“MyRestriction”, myrestrictionclass)); //****below is the important part**** count = c.setProjection(Projections.rowCount()).uniqueResult().hashCode(); }catch(Exception e){ e.printStackTrace(); } return count; }

Read More →