相关疑难解决方法(0)

Spring Data JPA和NamedEntityGraphs

目前我正在努力只能获取我需要的数据.findAll()方法需要根据其被调用的位置获取数据.我不想最终为每个实体图编写不同的方法.此外,我会避免调用实体管理员并自己形成(重复)查询.基本上我想在findAll方法中使用构建,但是使用我喜欢的实体图.任何机会?

@Entity
@Table(name="complaints")
@NamedEntityGraphs({
    @NamedEntityGraph(name="allJoinsButMessages", attributeNodes = {
            @NamedAttributeNode("customer"),
            @NamedAttributeNode("handling_employee"),
            @NamedAttributeNode("genre")
    }),
    @NamedEntityGraph(name="allJoins", attributeNodes = {
            @NamedAttributeNode("customer"),
            @NamedAttributeNode("handling_employee"),
            @NamedAttributeNode("genre"),
            @NamedAttributeNode("complaintMessages")
    }),
    @NamedEntityGraph(name="noJoins", attributeNodes = {

    })
})
public class Complaint implements Serializable{
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    private long id;

    private Timestamp date;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "customer")
    private User customer;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "handling_employee")
    private User handling_employee;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="genre")
    private Genre genre;

    private boolean closed;

    @OneToMany(mappedBy = "complaint", fetch = …
Run Code Online (Sandbox Code Playgroud)

jpa fetch spring-data-jpa entitygraph

47
推荐指数
4
解决办法
3万
查看次数

标签 统计

entitygraph ×1

fetch ×1

jpa ×1

spring-data-jpa ×1