• @NamedEntityGraphs --JPA按实体类对象参数中的字段排序问题得解决方法


    JPA按实体类对象参数中的字段排序问题得解决方法
    @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 = FetchType.LAZY, cascade = CascadeType.ALL) private List<ComplaintMessage> complaintMessages = new ArrayList<ComplaintMessage>(); //getters and setters }





    @Repository
    public interface ComplaintRepository extends JpaRepository<Complaint, Long>{
    
        List<Complaint> findByClosed(boolean closed);
    
        @EntityGraph(value = "allJoinsButMessages" , type=EntityGraphType.FETCH)
        @Override
        List<Complaint> findAll(Sort sort);
    }
  • 相关阅读:
    SQL 创建存储过程,让主键自增
    C# 实例练习(第二天)
    IT科技企业逻辑思维面试题
    C#学习——简介(第一天)
    C#中 ??、 ?、 ?: 、?.、?[ ]
    SQL Server类型与C#类型对应关系
    ios 键盘折叠
    html 水印效果
    JQuery筛选器全系列介绍
    将时间改为显示:几天前,几小时前,或者几分钟前
  • 原文地址:https://www.cnblogs.com/chenshuquan/p/9604023.html
Copyright © 2020-2023  润新知