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 ?

有帮助吗?

解决方案

Use:

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

Where:

startDate and endDate are your entity's dates.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top