我想使用 Spring Data Rest 来更新某些用户的行,但在运行时此查询在查询中添加了奇怪的“交叉联接”。
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=?
我唯一关心的是为什么添加“交叉连接”,因为它会给出 sql 错误
org.postgresql.util.PSQLException: ERROR: syntax error at or near "cross"
我直接通过rest invoke调用这个方法,也从mvc控制器调用这个方法,两种方法都会产生相同的错误
提前致谢。
找到解决方案,如中所述http://forum.spring.io/forum/spring-projects/data/114271-spring-data-jpa-modifying-query-failure http://forum.spring.io/forum/spring-projects/data/114271-spring-data-jpa-modifying-query-failure
“在批量 HQL 查询中不能指定隐式或显式的联接。子查询可以在 where 子句中使用,其中子查询本身可能包含联接。”(Hibernate 文档参考:http://docs.jboss.org/hibernate/core.../#batch-direct 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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)