我有以下类(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;
}
我想在阅读章节时检索章节列表,但我不想获取该章节。那可能吗 ?我无法使用 @Transient,因为我需要保留该部分。
注意:我将使用 spring 存储库中的 findAll,因此我不会使用 native 查询。
最佳答案
将sectionList 获取类型标记为lazy 并从类Section 中删除其getter。
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SECTION_ID")
private Section section;
关于java - JPA/Hibernate 只写字段,不读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53968487/