سؤال

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