I use Springboot, and I'd like to implement a "search" API for an entity that has an "OffsetDateTime" attribute.
The attribute is of type "OffsetDateTime" in my Hibernate entity :
@Column(name = "creation_date")
private OffsetDateTime creationDate;
The attribute that I get from the API is of type "OffsetDateTime" too.
I use the Springboot Specification, with the OffsetDateTime value as criteria.getValue() :
@Override
public Predicate toPredicate(Root<Job> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder builder) {
return builder.equal(root.get("creationDate"), criteria.getValue());
}
But the above code doesn't return me the entity with the specified date
However, the following code does :
@Override
public Predicate toPredicate(Root<Job> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder builder) {
Predicate predicate = builder.between(root.<OffsetDateTime>get("creationDate"),
((OffsetDateTime) criteria.getValue()).minus(1, ChronoUnit.MILLIS),
((OffsetDateTime) criteria.getValue()));
}
In my DB I have "2020-03-12 17:25:11.047", and the value I pass to the API is "2020-03-12T17:25:11.047+01:00". I'm in France, so I have a 1 hour offset, and the time is saved as a local time in the db, but that doesn't seem to be the problem as the second solution does return the entity I want.
Do you know why the first solution doesn't return me the entity, and how I could get the entity without having to set a 1 millisecond interval ?