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'm doing a query using CriteriaBuilder and I need to filter the holiday attribute 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);
The doubt is exactly in the last line
Predicate filterData = cb.equal (root.get ("holiday"), day);
How to get the holiday field only? That is, get the value of the getDayOfMonth () method of a LocalDate with the criteria?