Spring 数据 JPA JPQL Select child 属性

Spring data JPA JPQL Select Where on child property

我想要 select 漫画,其中包含按实际日期排列的章节列表。

但是那个查询 return 日期不正确。

@Query("SELECT m FROM Mangas m JOIN m.chapter c where c.release= '2018-07-30' GROUP BY m.id ORDER BY c.manga.id")
    public List<MangasEntity> buscarTodos();

我有域名

Mangas > List<Chapter>

@Entity
public class Mangas {

 //id, name, status, date

 @OneToMany
 private List<Chapters> Chapters;

 //Getter and Setter

@Entity   
public class Chapters {

    //id, release, chapterNumber

 @ManyToOne
 @JsonIgnore
 public Mangas manga;

我的查询 return 发布的章节列表不正确。我想要发布 2018-07-30.

的章节
[
    {
        "id": 12,            
        "name": "ONE PIECE",
        "status": "COMPLETE",
        "date": 2020,            
        "Chapters": [
            {
                "id": 22,
                "release": "2018-07-30",
                "chapterNumber": 777
            },
            {
                "id": 23,
                "release": "2018-07-30",
                "chapterNumber": 253
            },
            {
                "id": 26,
                "release": "2018-07-29",
                "chapterNumber": 777
            }
        ]
    }
]

使用JOIN FETCH解决。

@Query("SELECT DISTINCT m FROM Mangas m JOIN FETCH m.chapter c WHERE c.release = '2018-07-30' GROUP BY c.id")

Return 由 List<Chapters> 发行的漫画

[
    {
        "id": 12,
        "name": "ONE PIECE",
        "status": "COMPLETO",
        "date": 2020,
        "Chapters": [
            {
                "id": 22,
                "release": "2018-07-30",
                "chapterNumber": 777
            },
            {
                "id": 23,
                "release": "2018-07-30",
                "chapterNumber": 253
            }
        ]
    }
]