jpa从带有实体图加载的myobject中选择set< myobject>

dxxyhpgq  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(184)

我有一个实体:

@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 集合中的集合和段落对象必须没有惰性 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

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

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题