@SuppressWarnings("unchecked")
    public List<Task> getActiveForPeriod(Journal journal, Date startDate, Date endDate) {
        Query query = sessionFactory.getCurrentSession().createQuery(
                "from ru.stereohorse.polypus.model.Task task " +
                "left join fetch task.steps step " +
                "join fetch task.priority " +
                "join fetch task.status " +
                "where task.date >= :startDate " +
                "  and task.date < :endDate " +
                "  and task.journal = :journal" +
                "  and task.isDeleted = false " +
                "  and (step.isDeleted = false or step is null) " +
                "order by task.date, step.date")
                .setDate("startDate", startDate)
                .setDate("endDate", endDate)
                .setEntity("journal", journal);

        return query.list();
    }