Spring Boot DataTable TIMESTAMP range search

Spring Boot DataTable TIMESTAMP range search

wallac3ggwallac3gg Posts: 2Questions: 0Answers: 0

Timestamp FIELD - "created" ( Postgresql )

In postgresql I have dates in format

createdDate : "2018-11-01 23:51:33.534" (TIMESTAMP WITHOUT TIME ZONE)

I would like to retrieve all orders for 2018-11-01.

Spring DATA JPA - DATATABLE METHOD

@override
public Predicate toPredicate(Root<Parlamentares> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {

Expression<Timestamp> createdDate = root.get("created").as(Timestamp.class);

if (dateBegi != null && dateEnd != null) {
return criteriaBuilder.between(createdDate, dateBegi, dateEnd);
} else if (dateBegi != null) {
return criteriaBuilder.greaterThanOrEqualTo(createdDate, dateBegi);
} else if (dateEnd != null) {
return criteriaBuilder.lessThanOrEqualTo(createdDate, dateEnd);
} else {
return criteriaBuilder.conjunction();
}
}

Everything works fine when i'm using "createdDate DATE column".

dateBegi : "2018-11-01" comes from daterangepick.

How to resolve this problem? Any ideia ?

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    This is really more of a Postgres question that a DataTables one, so So might be a better option, however, the way I would do it myself is to use the extract function in postgres which will allow you to extract the date part without the time and do a direct comparison against another date.

    Allan

  • wallac3ggwallac3gg Posts: 2Questions: 0Answers: 0

    If you got this problem, you have to reset the value of the "colmunParameter" in the DataTablesInput object.

    SOLUTION :

    public DataTablesOutput<Parla> listParla(@Valid DataTablesInput input) {

        Column parameter0 = input.getColumns().get(6);
        Specification<Parla> additionalSpecification  = new DateSpecification(parameter0.getSearch().getValue());
        parameter0.getSearch().setValue(""); <---
        return repository.findAll(input, additionalSpecification );
    }
    

    Spring Data Jpa DATATABLES server side, date RANGE filter with TIMESTAMP column POSTGRESQL. /CLOSED

This discussion has been closed.