spring 数据剩余更新产生交叉连接 sql 错误
spring data rest update produce cross join sql error
我想使用 spring 数据 rest 来更新特定用户的行,但是在 运行 这个查询中有奇怪的 "cross join" 添加到查询中。
spring数据休息方式
@Modifying
@Transactional
@Query("Update Notification n SET n.noticed = true Where n.notificationPost.owner.userId = 1 ")
public void postNoticed();
运行 创建查询的时间
Hibernate: update notification cross join set noticed=true where owner_id=?
我唯一担心的是为什么添加 "cross join",因为它给出了 sql 错误
org.postgresql.util.PSQLException: ERROR: syntax error at or near "cross"
我直接通过 rest invoke 调用这个方法,也从 mvc controller 调用,两种方式都产生相同的错误
提前致谢。
已找到 http://forum.spring.io/forum/spring-projects/data/114271-spring-data-jpa-modifying-query-failure
中所述的解决方案
"No joins, either implicit or explicit, can be specified in a bulk HQL query. Sub-queries can be used in the where-clause, where the subqueries themselves may contain joins. "(Hibernate 文档参考:http://docs.jboss.org/hibernate/core.../#batch-direct)。”
所以我编辑了代码以使用子查询
@Modifying
@Transactional
@Query("Update Notification n SET n.noticed = true Where n.notificationPost.postId in (SELECT n2.notificationPost.postId FROM Notification n2 where n2.notificationPost.owner.userId =:#{#security.principal.user.userId}) ")
public int postNoticed();
我想使用 spring 数据 rest 来更新特定用户的行,但是在 运行 这个查询中有奇怪的 "cross join" 添加到查询中。
spring数据休息方式
@Modifying
@Transactional
@Query("Update Notification n SET n.noticed = true Where n.notificationPost.owner.userId = 1 ")
public void postNoticed();
运行 创建查询的时间
Hibernate: update notification cross join set noticed=true where owner_id=?
我唯一担心的是为什么添加 "cross join",因为它给出了 sql 错误
org.postgresql.util.PSQLException: ERROR: syntax error at or near "cross"
我直接通过 rest invoke 调用这个方法,也从 mvc controller 调用,两种方式都产生相同的错误
提前致谢。
已找到 http://forum.spring.io/forum/spring-projects/data/114271-spring-data-jpa-modifying-query-failure
中所述的解决方案"No joins, either implicit or explicit, can be specified in a bulk HQL query. Sub-queries can be used in the where-clause, where the subqueries themselves may contain joins. "(Hibernate 文档参考:http://docs.jboss.org/hibernate/core.../#batch-direct)。”
所以我编辑了代码以使用子查询
@Modifying
@Transactional
@Query("Update Notification n SET n.noticed = true Where n.notificationPost.postId in (SELECT n2.notificationPost.postId FROM Notification n2 where n2.notificationPost.owner.userId =:#{#security.principal.user.userId}) ")
public int postNoticed();