Problems with between LocalDate Predicate

2019-07-20 05:32发布

问题:

This is my table

The selected column is the one that I'm using in Predicate

My first approach was

  public void betweenPredicate(String attrib, LocalDate value, LocalDate value2) {
        Predicate predicate = builder.between(entity.<LocalDate> get(attrib), builder.literal(value), builder.literal(value2));                
        predList.add(predicate);
    }

But in that way some date are missing, so I change to this

 public void betweenPredicate(String attrib, LocalDate value, LocalDate value2) {
        Predicate predicate = builder.and(builder.<LocalDate>greaterThan(entity.get(attrib), value),
                builder.<LocalDate>lessThan(entity.get(attrib), value2));
        predList.add(predicate);
    }

In that way works perfeclty, so my question is What is the main different betweent this two way, Am I done something wrong?

EDIT

This is my screen I'm using netbeans 8.2 with DatePicker from swingx 1.6

DatePicker send me Date, but my class receive LocalDate so a have this Convert Method

public static LocalDate dateToLocalDate(Date data) {
        if (data != null) {
            return data.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        } else {
            return null;
        }
    }

and I added two println at betweenPredicate to see how the values are getting there and this is the output

V: 2018-02-01
V2: 2018-02-16