下面是查询工作正常
@Query("SELECT city.id as id,city.latitude as latitude, city.longitude as longitude, \n" +
"(SELECT cityTrans.name " +
" FROM city.listOfCityTrans as cityTrans " +
" WHERE cityTrans.languageId=:languageId AND cityTrans.cityId=city.id)" +
" AS name, \n" +
"(SELECT provinceTrans.name " +
" FROM city.province AS province JOIN province.listOfProvinceTrans AS provinceTrans " +
" WHERE provinceTrans.languageId=:languageId AND provinceTrans.provinceId=city.provinceId)" +
" AS provinceName, \n" +
"(SELECT countryTrans.name " +
" FROM city.province AS province JOIN province.country.listOfCountryTrans AS countryTrans " +
" WHERE countryTrans.languageId=:languageId AND countryTrans.countryId=city.provinceId)" +
" AS countryName, province.id as provinceId,province.countryId as countryId \n" +
" FROM City as city")
Page<CitySummary> findCities(@Param("languageId") Integer languageId, Pageable pageable);
但是当我通过排序参数?sort=name
然后它正在创建错误的查询
SELECT city.id as id,city.latitude as latitude, city.longitude as longitude,
\n(SELECT cityTrans.name FROM city.listOfCityTrans as cityTrans WHERE
cityTrans.languageId=:languageId AND cityTrans.cityId=city.id) AS name,
\n(SELECT provinceTrans.name FROM city.province AS province JOIN
province.listOfProvinceTrans AS provinceTrans WHERE
provinceTrans.languageId=:languageId AND
provinceTrans.provinceId=city.provinceId) AS provinceName, \n(SELECT
countryTrans.name FROM city.province AS province JOIN
province.country.listOfCountryTrans AS countryTrans WHERE
countryTrans.languageId=:languageId AND
countryTrans.countryId=city.provinceId) AS countryName, province.id as
provinceId,province.countryId as countryId \n FROM
com.pro.api.model.City as city order by cityTrans.name asc
^
有人能说出为什么会这样吗?
答案 0 :(得分:2)
我认为MVC到JPA路径仅适用于实体定义,而不适用于Object[]
结果,因此如果您的City
实体没有name
属性,则JPA会尝试找到另一个字段匹配,即cityTrans