首页 > 解决方案 > 在 hql 中选择新的子查询列表

问题描述

我正在尝试使用属性部分中的子查询。当子查询只返回一个结果时,这很好用。否则显示错误。

[2019-12-30 11:24:26] [21000] 错误:用作表达式的子查询返回的行不止一行

    @Query("select new com.example.rest.ShiftResponse(s.id, s.displayTitle, s.startTime, s.endTime, s.max, (select comm from ShiftGroup sg inner join sg.committee comm where sg.shift.id = s.id)) from Shift s where s.event.id = ?1")

这是构造函数的签名

    public ShiftResponse(Long id, MultilangText displayTitle, LocalDateTime startTime, LocalDateTime endTime, Integer max, List<Committee> committees) {

除此以外还有什么方法可以指定我希望该参数是一个列表?

标签: postgresqlspring-bootsubqueryhql

解决方案


你检查过这个链接吗?新对象(..)中的 HQL 新列表(..)

在我看来,这是一个类似的问题。它回答了你的问题吗?


推荐阅读