try {
session = HibernateUtils.getCurrentSession();
Criteria crit = session.createCriteria(Invoice.class);
crit.add(Restrictions.eq("year", year));
crit.setProjection(Projections.max("number"));
Long maxNumberLong = (Long) crit.uniqueResult();
if (maxNumberLong != null)
maxNumber = maxNumberLong.intValue();
crit.setProjection(null);
crit.setResultTransformer(Criteria.ROOT_ENTITY);
} catch (HibernateException ex) {