Spring mvc - Querydsl:不能使用distinct与orderBy距离

时间:2015-07-20 15:58:35

标签: spring spring-mvc jpa spring-boot querydsl

我目前正在尝试在Spring boot 1.2.2下为REST Web服务构建一个分页请求。我正在使用'com.mysema.querydsl:querydsl-jpa:3.6.2'。

以下是我要尝试运行的代码:

        if(point != null) {
        LOGGER.debug(point.toString());
        query = query.orderBy(merchant.point.distance(point).asc());
    } else {
        query = query.orderBy(merchant.mercName.asc());
    }

为了避免多次返回同一行,我放了一个“query.distinct”,它适用于某些条件:

2015-07-20 17:36:58.363 ERROR 5676 --- [nio-8180-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERREUR: pour SELECT DISTINCT, ORDER BY, les expressions doivent apparaître dans la liste SELECT


2015-07-20 17:36:58.375 DEBUG 5676 --- [nio-8180-exec-1] o.s.web.servlet.DispatcherServlet        : Could not complete request

org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:231)

我认为问题在于这个问题。这个想法是,如果用户给我坐标,我必须能够通过距离ASC订购我的商家。

如果该点为NULL,则没有问题,我的商家按名称ASC订购。但如果该点包含坐标,我就有这个错误:

    select distinct merchant
from Merchant merchant
  inner join merchant.merchantBusinessTypes as merchantBusinessType
where merchant.idSupermerchant is not null
order by distance(merchant.point, ?1) asc

如果我打印我的查询,它就给了我:

this.monthCalendar1.AnnuallyBoldedDates = 
            new System.DateTime[] { new System.DateTime(2015, 7, 20, 0, 0, 0, 0),
                                    new System.DateTime(2015, 7, 21, 0, 0, 0, 0)};

这对我来说似乎是正确的。我们正在使用带有空间数据库的PostgresSQL。问题是,如果我从查询中删除“.distinct()”,则没有问题,但重复的商家......

熟悉该图书馆的人有想法吗?我坚持使用它,我不知道除了在纯HQL中重新编码这个查询:)

谢谢!

0 个答案:

没有答案