我有一個 Hibernate 類,其中包含如下字段:@OneToMany(
orphanRemoval = true,
mappedBy = "others",
cascade = CascadeType.ALL,
fetch = FetchType.LAZY)
private Set<AnotherEntity> otherEntities;我們啟用了延遲加載,這樣它就不會一次加載所有內(nèi)容。但我希望擁有它,這樣它就不會加載所有內(nèi)容 - 如果我想加載它,我將使用一個(Hibernate)查詢來獲取所有必要的信息。如果我只加載主要對象,則不應(yīng)加載其他任何對象。entity.getOtherEntities() 應(yīng)該返回 null - 即使有數(shù)據(jù)。有可能以某種方式實現(xiàn)這一目標(biāo)嗎?
如何將 Hibernate FetchType 設(shè)置為“none”而不是“Eager”或“Lazy”
慕運維8079593
2023-11-01 17:03:13