[英]CriteriaBuilder in JPA with the method between
I'm trying to use the CriteriaBuilder.between but I have an error, the code is this: 我正在尝试使用CriteriaBuilder.between,但是出现错误,代码是这样的:
public List<Oferta> findByFechaFinOferta(Date fechaInicio,Date fechaFin){
CriteriaBuilder cBuilder = em.getCriteriaBuilder();
CriteriaQuery<Oferta> cQuery =cBuilder.createQuery(Oferta.class);
Root<Oferta> a = cQuery.from(Oferta.class);
ParameterExpression <String> param = cBuilder.parameter(String.class);
cQuery.select(a).where(cBuilder.between(a.get("fechaFin"),fechaInicio,fechaFin));
TypedQuery<Oferta> tQuery = em.createQuery(cQuery);
List<Oferta> oferta = tQuery.getResultList();
return oferta;
}
The cQuery.select(a).where(cBuilder.between(a.get("fechaFin"),fechaInicio,fechaFin)); cQuery.select(a).where(cBuilder.between(a.get(“ fechaFin”),fechaInicio,fechaFin))); is wrong, but how I can do to make it work out?.
是错的,但是我该怎么做才能解决?
Thanks so much 非常感谢
In this way I can answer myself: 这样我可以回答自己:
Predicate predicate = cBuilder.between(a.get(Oferta_.fechaFin),fechaInicio,fechaFin);
cQuery.select(a).where(predicate);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.