在JSON序列化期间获取JPA FetchType.LAZY集合

时间:2017-03-22 16:24:46

标签: spring rest jpa spring-boot

在对相应控制器端点的休息调用期间获取oneToMany带注释的集合。该集合是一个懒惰的获取列表 如何避免获取该集合? 这是一个典型的大型集合,除非明确要求,否则不应该连线。

提前感谢。

    package xxx;

        import java.math.BigDecimal;
        import java.util.Calendar;
        import java.util.List;

        @Entity(name = "Ortaklik")
        // @Table(name="ortaklik",uniqueConstraints={@UniqueConstraint(columnNames={"id"})})
        @NamedQueries({
        @NamedQuery(name = "Ortaklik.findMaxOrtaklik", query = "SELECT o FROM Ortaklik o WHERE o.id=(SELECT MAX(o.id) FROM o WHERE o.ortak.id=:ortakid )") })
        @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class,property="@ortaklikId")

        public class OrtaklikEntity {

            @Id
            @GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_Ortaklik")
            @SequenceGenerator(sequenceName = "seq_Ortaklik", name = "seq_Ortaklik")
            private Long id;
            @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
            @JoinColumn(name = "ortak_id")
            @JsonBackReference
            private OrtakEntity ortak;
/**********************THIS IS THE MENTIONED COLLECTION****///////
            @OneToMany(mappedBy="ortaklik",fetch=FetchType.LAZY)
            private List<OngorulenAidatOdemePlanTaksitEntity> aidatList;

            public OrtaklikEntity() {
            }


            public List<OngorulenAidatOdemePlanTaksitEntity> getAidatList() {
                return aidatList;
            }

            public void setAidatList(List<OngorulenAidatOdemePlanTaksitEntity> aidatList) {
                this.aidatList = aidatList;
            }




        }

The inverse side of the relationship is as follows

    public class OngorulenAidatOdemePlanTaksitEntity implements Serializable, Comparable {

        // <editor-fold defaultstate="collapsed" desc="alanlar">
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_ongrln_aidat_oplani_tkst")
        @SequenceGenerator(sequenceName = "seq_ongrln_aidat_oplani_tkst", name = "seq_ongrln_aidat_oplani_tkst")
        private Long id;

        @ManyToOne 
        @JoinColumn(name="ortaklik_id")
        private OrtaklikEntity ortaklik;

0 个答案:

没有答案