Problems with JPA Hibernate Query with ‘Interval’

In that case use the JPA provided functionality , where native sql code is not required.

  List<Order> findALLByCreatedDateBefore(Date fromDate);

and on java side invoke it

public void findOrders() {
    date = setMonthToJavaUtilDate(new Date(), -6);
    yourRepository.findOrders(fromDate)
    //your logic...
}

private Date setMonthToJavaUtilDate(Date date, int month) {
    Calendar now = Calendar.getInstance();
    now.setTime(date);
    now.add(Calendar.MONTH, month);
    return now.getTime();
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top