加入获取与加入,您需要在这里获取吗?

时间:2019-07-08 16:43:37

标签: java jpql

案例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还是加入足够?

0 个答案:

没有答案