我正在编写一个应用程序,在这个应用程序中,公共汽车司机可以在他们处理的路线上与孩子的父母进行集体交谈。
我想在公共汽车到达最后一站之前向所有聊天发送信息。
我尝试过这个查询,但是它总是返回0的结果。当它应该至少返回一次的时候。
1 | @Query("select g from GroupChat g " +
2 | "join g.route r " +
3 | "join r.bus b " +
4 | "join b.mostRecentStop mrs " +
5 | "join r.stops s " +
6 | "join s.children c " +
7 | "where r.routeId = :routeId " +
8 | "and s.stopTime <= mrs.stopTime " +
9 | "and g.childId = c.childId ")
10|Set<GroupChat> getAllGroupChatsOnRouteForPreviousStops(@Param("routeId") short routeId);GroupChats PK是routeId-childId
第2行获取与群聊相关联的路由。
第3行获取该路线的公共汽车。
第4行获取公共汽车到达的最近一站。
第5行获取路线上的所有站点。
第6行获取路线上的所有子站(即每个站中的每个子站)。
第7行只对查询的路由进行筛选。
第8行在最近的停止之前对停止进行筛选
第9行只为剩余停止上的独生子女进行组聊天筛选。
我做错了什么?
发布于 2018-09-13 13:40:27
因为这涉及JPQL中的复杂查询,所以最好使用本机查询。
@Query(value="select g from GroupChat g
join g.route r
join r.bus b
join b.mostRecentStop
join r.stops s
join s.children c
where r.routeId = :routeId
and s.stopTime <= mrs.stopTime
and g.childId = c.childId",
nativeQuery=true
)
Set<GroupChat> getAllGroupChatsOnRouteForPreviousStops(@Param("routeId") short routeId);https://stackoverflow.com/questions/52298543
复制相似问题