提取实体时集合中重复

时间:2018-07-11 13:48:35

标签: hibernate spring-boot spring-data-jpa repository hibernate-mapping

我将Spring Data存储库用作我的DAO,并且在获取此实体时发现了一个问题:

路线

public class Route {
    @OneToMany
    List<Stop> stops;

    @OneToOne
    Bus bus;
}

停止

public class Stop {
    @ManyToOne
    Route route;
}

公共汽车

public class Route {
    @OneToOne
    Stop prev;

    @OneToOne
    Stop next;

    @OneToOne
    Route route;
}

为简洁起见,我省略了大多数细节。

当前,当我获取一个Route实体时,它使用了一个外部联接,似乎在路由中的列表不正确。

我可以使用Java 8流和与众不同的方法来解决它,但是我只想解决这个躲闪的请求。 我还需要保持顺序,所以我不能将Stops的集合定义为Set。

任何建议将不胜感激!

完整的select语句:

select
    route0_.route_id as route_id1_12_0_,
    route0_.chaperone_id as chaperon4_12_0_,
    route0_.route_name as route_na2_12_0_,
    route0_.type as type3_12_0_,
    schedules1_.route_id as route_id2_13_1_,
    schedules1_.day_of_week as day_of_w1_13_1_,
    schedules1_.day_of_week as day_of_w1_13_2_,
    schedules1_.route_id as route_id2_13_2_,
    schedules1_.completed as complete3_13_2_,
    stops2_.route_id as route_id2_14_3_,
    stops2_.stop_id as stop_id1_14_3_,
    stops2_.stop_id as stop_id1_14_4_,
    stops2_.route_id as route_id2_14_4_,
    stops2_.stop_address as stop_add3_14_4_,
    stops2_.stop_time as stop_tim4_14_4_,
    children3_.stop_id as stop_id1_7_5_,
    child4_.child_id as child_id2_7_5_,
    child4_.child_id as child_id1_5_6_,
    child4_.child_firstname as child_fi2_5_6_,
    child4_.child_lastname as child_la3_5_6_,
    child4_.child_medical as child_me4_5_6_,
    child4_.registered as register5_5_6_,
    bus5_.route_id as route_id1_3_7_,
    bus5_.lat as lat2_3_7_,
    bus5_.lon as lon3_3_7_,
    bus5_.most_recent_stop as most_rec5_3_7_,
    bus5_.next_stop as next_sto6_3_7_,
    bus5_.time_diff as time_dif4_3_7_ 
from
    route route0_ 
left outer join
    schedule schedules1_ 
        on route0_.route_id=schedules1_.route_id 
left outer join
    stop stops2_ 
        on route0_.route_id=stops2_.route_id 
left outer join
    gets_on_at children3_ 
        on stops2_.stop_id=children3_.stop_id 
left outer join
    Child child4_ 
        on children3_.child_id=child4_.child_id 
left outer join
    bus bus5_ 
        on route0_.route_id=bus5_.route_id 
where
    route0_.route_id=? 
order by
    stops2_.stop_time

0 个答案:

没有答案
相关问题