1

I have the following class :

    public class Section {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    private Long id;

 ...
    @ManyToOne
    @JoinColumn(name = "SECTION_ID")
    private Section section;  // need this write only

    @OneToMany
    private List<Section> sectionList;

}

I want to retrieve the section list when reading the section, but I don't want to get the section. is that possible ? I can't use @Transient because I need the section to be persisted.

Note: I will use findAll from spring repository so I will not use native query.

Mohammad Karmi
  • 1,403
  • 3
  • 26
  • 42

1 Answers1

0

Mark the sectionList fetch type as lazy and remove its getter from the class Section.

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SECTION_ID")
private Section section;
Deepak Kumar
  • 1,246
  • 14
  • 38
Aditya Narayan Dixit
  • 2,105
  • 11
  • 23