Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询中的JAVA JPA日期间问题_Java_Jpa - Fatal编程技术网

查询中的JAVA JPA日期间问题

查询中的JAVA JPA日期间问题,java,jpa,Java,Jpa,尝试在CriteriaQuery中使用between,但不断遇到编译问题 数据作为参数传递,请参见以下代码: public List<PlanTacticBuyFile> getByTacticIdsDates(List<Integer> ids, Date startDate, Date endDate) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<PlanT

尝试在CriteriaQuery中使用between,但不断遇到编译问题

数据作为参数传递,请参见以下代码:

public List<PlanTacticBuyFile> getByTacticIdsDates(List<Integer> ids, Date startDate, Date endDate)
{
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<PlanTacticBuyFile> q = builder.createQuery(PlanTacticBuyFile.class);
    Root<PlanTacticBuyFile> c = q.from(PlanTacticBuyFile.class);
    ParameterExpression<Date> d = builder.parameter(Date.class);
    q.where(builder.and(c.get("tacticId").in(ids),
            builder.between(builder.literal(startDate), c.get("startDate"), c.get("endDate"))));
公共列表getByTacticId(列表ID、日期开始日期、日期结束日期)
{
CriteriaBuilder=em.getCriteriaBuilder();
CriteriaQuery q=builder.createQuery(PlanTacticBuyFile.class);
根c=q.from(PlanTacticBuyFile.class);
ParameterExpression d=builder.parameter(Date.class);
q、 其中(建造商和(c.get)(“tacticId”)在(ids)中,
builder.between(builder.literal(startDate)、c.get(startDate)、c.get(endDate));
在中间调用的第一个参数上出现编译错误


谢谢!

如何参数化您的CriteriaQuery?我在您的代码中看到了date ParameterExpression对象,但我不确定您是否在其他地方使用过它

CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<PlanTacticBuyFile> q = builder.createQuery(PlanTacticBuyFile.class);
Root<PlanTacticBuyFile> c = q.from(PlanTacticBuyFile.class);

ParameterExpression<Date> date = builder.parameter(Date.class, "startDate");
q.where(builder.and(c.get("tacticId").in(ids),
        builder.between(date, c.get("startDate"), c.get("endDate"))));
...

em.createQuery(q).setParameter("startDate", startDate).getResultList();
CriteriaBuilder=em.getCriteriaBuilder();
CriteriaQuery q=builder.createQuery(PlanTacticBuyFile.class);
根c=q.from(PlanTacticBuyFile.class);
ParameterExpression date=builder.parameter(date.class,“startDate”);
q、 其中(建造商和(c.get)(“tacticId”)在(ids)中,
建造商之间(日期,c.get(“开始日期”),c.get(“结束日期”));
...
setParameter(“startDate”,startDate).getResultList();

是的,我无法确定在发送的参数和查询之间的连接在哪里!谢谢!