Hibernate criteria Restrictions:- how to fetch current and last month data
<p>Here is my method to get the specific month and year data from created date.</p>

<pre><code>    @Override
    public List getMonthlyOrdersSummary(LabOrderConditions labOrderConditions) {
        Criteria criteria = getCurrentSession().createCriteria(LabOrder.class);

        criteria.add(Restrictions.gt("orderNo", 0));
        if (StringUtils.isNotBlank(labOrderConditions.getClientCode()))
            criteria.add(Restrictions.eq("clientCode", labOrderConditions.getClientCode()));

        if (labOrderConditions.getAccountCodesList() != null) {
            criteria.add(Restrictions.in("practice.code", labOrderConditions.getAccountCodesList()));
        }


        if (StringUtils.isNotBlank(labOrderConditions.getClientsCodes())) {
            if (labOrderConditions.getCallingPlace().equalsIgnoreCase("allClients")) {
                List&lt;String&gt; items = Arrays.asList(labOrderConditions.getClientsCodes().split("\\s*,\\s*"));
                criteria.add(Restrictions.in("clientCode", items));
            }
        }

        criteria.add(Restrictions.sqlRestriction("YEAR(createdDate)=" + labOrderConditions.getYear()));
        ProjectionList projectionList = Projections.projectionList();

        if (labOrderConditions.getCallingPlace().equalsIgnoreCase("allClients")) {
            projectionList.add(Projections.groupProperty("clientCode"), "clientCode");
        }

        projectionList.add(Projections.sqlGroupProjection("MONTHNAME(createdDate) as orderMonthName", "MONTHNAME(createdDate)",
                new String[] { "orderMonthName" }, new Type[] { StandardBasicTypes.STRING }));
        projectionList.add(Projections.sqlGroupProjection("Month(createdDate) as orderMonthNo", "Month(createdDate)", new String[] { "orderMonthNo" },
                new Type[] { StandardBasicTypes.INTEGER }));

        projectionList.add(Projections.rowCount());
        criteria.setProjection(projectionList);
        criteria.addOrder(org.hibernate.criterion.Order.asc("createdDate"));
        return criteria.list();
    }
</code></pre>

<p>So how to write restriction for current and last month.</p>

<p>I just want something like <code>criteria.add(Restrictions.in("MONTHNAME(createdDate)", labOrderConditions.getCompareMonthList()));</code></p>

<p>Please if anyone have any suggestion share with me.</p>

<p>Thanks
Sitansu</p>