0

我有那个实体:

@NamedEntityGraph(
        name = "paragraph-graph-questions",
        attributeNodes = {
                @NamedAttributeNode(value = "questions")
        })
@Entity
@Table(name = "paragraphs")
public class Paragraph {

    @Id
    private Integer id;

    @OneToMany(mappedBy = "paragraph")
    private Set<Question> questions;

    @OneToMany
    @JoinTable(
            name = "sub_paragraphs",
            joinColumns = @JoinColumn(name = "paragraph_id"),
            inverseJoinColumns = @JoinColumn(name = "sub_paragraph_id")
    )
    private Set<Paragraph> subParagraphs;
}

我尝试获取subParagraphs集合,并且集合中的 Paragraph 对象必须没有惰性questions集合。我使用该查询:

@EntityGraph(value = "paragraph-graph-questions")
@Query("SELECT p.subParagraphs FROM Paragraph p WHERE p.id=:id")
Set<Paragraph> getAllSubParagraphs(int id);

它抛出异常:

java.lang.IllegalArgumentException: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list

在我的情况下我可以做些什么来修复异常?

4

0 回答 0