需查詢角色時一併載入其模組,及模組下的按鈕(三層關聯)。
session.CreateCriteria()
.SetFetchMode("Modules", FetchMode.Join)
.SetFetchMode("Modules.Buttons", FetchMode.Join)
.List();
from Role r left join fetch r.modules m left join fetch m.buttons。注意:多層 `join fetch` 可能產生笛卡兒積導致資料行數暴增,建議改用**批次抓取**(`batch-size`)或**子查詢**,或在 Service 層分步載入並組裝 DTO。