【问题标题】:return selected properties with Joined complete entity返回具有已连接完整实体的选定属性
【发布时间】:2023-04-07 15:07:02
【问题描述】:

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

 @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);

如您所见,我的意图是返回 citylistOfEquipmentlistOfSlot

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

请帮助我找到正确的方法

【问题讨论】:

  • 那部分是什么意思? :FROM Gym g INNER JOIN g.city as city
  • @Berger 只需要选定的城市,所以FROM Gym g INNER JOIN g.city as city WHERE city.id=:cityId

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


【解决方案1】:

尝试像下面这样加入。

FROM Gym g INNER JOIN  city

【讨论】:

    【解决方案2】:

    试试这个:

    @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 属性在健身房内,因此您可以直接到达。

    【讨论】:

      猜你喜欢
      • 2016-03-31
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多