【问题标题】:JPQL Query yields no results using BETWEEN operatorJPQL 查询使用 BETWEEN 运算符不产生任何结果
【发布时间】:2015-09-17 13:02:41
【问题描述】:

使用此方法时:

    public static List<Image> listImages(double longitude, double latitude) {
    Query q = em.createQuery("select e from Image as e where e.long_ between " 
+(longitude - 0.1)+" and "+(longitude + 0.1)+ " and e.lat between "+(latitude-0.1)+" and "+(latitude+0.1)+" order by e.id desc");

    @SuppressWarnings("unchecked")
    List<Image> imageList = q.getResultList();
    System.out.println("Size: " + imageList.size());
    return imageList;
}

imageList 返回为空,imageList.size() 返回 0。 即使查询应该根据查询从我的数据库中返回至少几行。

我不知道该怎么做,因为我没有收到任何错误。它只是空着回来。如果我应该提供其他东西,请告诉我!

【问题讨论】:

  • lat和long_字段的数据库类型是什么,生成的SQL是什么,如果自己运行SQL会怎样?

标签: jpa jpql


【解决方案1】:

我才意识到出了什么问题。只是我搞砸了。

    public Image(String url, double longitude, double latitude, Time time) {
    this.url = url;
    this.lat = latitude;
    this.long_ = longitude;
    this.moment = time;
}

我在这里放错了经度和纬度,所以当我在数据库中插入一些东西时,经度和纬度交换了位置。这就是为什么我没有得到任何结果。对不起!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-28
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    • 2021-05-27
    • 1970-01-01
    • 2013-01-09
    相关资源
    最近更新 更多