Question

In SQL, we can check the date overlaps as

SELECT (DATE '2001-02-16', DATE '2001-12-21') OVERLAPS
   (DATE '2001-10-30', DATE '2002-10-30');

How can we imitate the same using hibernate Restrictions ?

Was it helpful?

Solution

Use:

 criteria.add(Restrictions.ge("endDate", startDate2));
 criteria.add(Restrictions.le("startDate", endDate2));

Where:

startDate and endDate are your entity's dates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top