class RunDao extends BaseHibernateEntityDao<RunHibernateEntity> {

    public RunHibernateEntity findLastInSequenceFor(EventHibernateEntity event) {
        Class<RunHibernateEntity> runClass = RunHibernateEntity.class;
        CriteriaBuilder builder = currentSession().getCriteriaBuilder();
        CriteriaQuery<RunHibernateEntity> criteriaQuery = builder.createQuery(runClass);
        Root<RunHibernateEntity> runRoot = criteriaQuery.from(runClass);
        criteriaQuery.select(runRoot);
        criteriaQuery.where(builder.equal(runRoot.get("event"), event));
        criteriaQuery.orderBy(builder.desc(runRoot.get("sequence")));
        Query<RunHibernateEntity> query = currentSession().createQuery(criteriaQuery);
        query.setMaxResults(1);
        try {
            return query.getSingleResult();
        } catch (NoResultException nre) {
            return null;
        }
    }

    @Inject public  RunDao(SessionFactory sessionFactory);

}