案例1:
设想以下情况,我有一个用户具有一个OneToMany映射,如下所示:
@OneToMany(mappedBy = "host", cascade = CascadeType.ALL)
@OrderBy("takesPlaceOn")
private List<CookEvent> hostedEvents;
我想选择所有hostedEvents,其中事件takesPlaceOn> CURRENT_TIMESTAMP如下:
SELECT c FROM User u
JOIN (FETCH) u.hostedEvents c
WHERE u.id = :id AND c.takesPlaceOn > CURRENT_TIMESTAMP
我需要在此处加入FETCH还是加入足够?
案例2: 想象一下第二个JPQL查询:
SELECT DISTINCT(c) FROM User u
JOIN (FETCH) u.tags t
JOIN (FETCH) t.cookEvents c
WHERE u.id = :id AND c.takesPlaceOn > CURRENT_TIMESTAMP
我需要在这里加入FETCH还是加入足够?