How to compare the day of a Localdate in Criteriabuilder

Asked

Viewed 257 times

1

I have an entity that has a Localdate field.

    @Entity
    @Table(name="feriado")
    public class Feriado implements Serializable{

      private static final long serialVersionUID = 1L;

      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;

      @NotNull
      @Column(nullable=false,unique=true)
      @Convert(converter=LocalDateConverter.class)
      private LocalDate feriado;

      @NotNull @Size(min=5,max=100)
      @Column(nullable=false,length=100)
      private String descricao;

      @Column(name="dia_fixo",nullable = false, columnDefinition = "TINYINT", length = 1)
      private Boolean diaFixo;

      // get and sets

   }

I am making a query using Criteriabuilder and need to filter the attribute holiday by day

CriteriaBuilder cb = entityManager.getCriteriaBuilder();

CriteriaQuery<Long> cq = cb.createQuery(Long.class);

Root<Feriado> root = cq.from(Feriado.class);

cq.select(cb.count(root));

//Parametros
List<Predicate> criteria = new ArrayList<>();

Predicate filtroData = 
    cb.equal(root.<LocalDate>get("feriado"), dia);

Doubt is exactly on the last line

Predicate filtroData = cb.Equal(root.get("holiday"), day);

How to get only the Holiday Camp Day ? That is, get the value of the getDayOfMonth() method of a Localdate with the criteria?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.