使用已加入的完整实体返回选定的属性

时间:2017-11-17 13:15:08

标签: java postgresql spring-boot spring-data-jpa hql

我需要返回自定义响应,所以我尝试了以下查询

 @Query("SELECT g.name as name,g.id as id, city as city, g.listOfEquipment as listOfEquipment,g.listOfSlot as listOfSlot" +
            " FROM Gym g INNER JOIN g.city as city " +
            "WHERE city.id=:cityId")
    List<Map<String, Object>> listing(@Param("cityId") Integer cityId, Pageable pageable);

您可以看到我的意图是返回citylistOfEquipment以及listOfSlot

我认为这会有效,但不幸的是它不起作用 我得到了PSQLException: ERROR: syntax error at or near "."

请帮助我找到正确的方法

2 个答案:

答案 0 :(得分:1)

尝试加入如下。

FROM Gym g INNER JOIN  city

答案 1 :(得分:0)

试试这个:

@Query("SELECT g.name as name,g.id as id, g.city as city, g.listOfEquipment as 
listOfEquipment, g.listOfSlot as listOfSlot" +
        " FROM Gym g " +
        "WHERE g.city.id=:cityId")

您的city酒店位于健身房内,因此您可以直接到达。