spring data rest update产生交叉连接sql错误

use*_*743 4 spring-data spring-data-rest

我想使用spring data rest更新某些用户的行,但在运行时,此查询会在查询中添加奇怪的"交叉连接".

弹簧数据休息方法

 @Modifying
@Transactional
@Query("Update Notification n SET n.noticed = true Where n.notificationPost.owner.userId = 1 ")
public void postNoticed();
Run Code Online (Sandbox Code Playgroud)

运行时创建的查询

Hibernate: update notification cross join  set noticed=true where owner_id=?
Run Code Online (Sandbox Code Playgroud)

我唯一关心的是为什么添加"交叉连接",因为它给出了sql错误

org.postgresql.util.PSQLException: ERROR: syntax error at or near "cross"
Run Code Online (Sandbox Code Playgroud)

我通过rest调用直接调用这个方法,并且从mvc控制器调用这两种方法产生相同的错误

提前致谢.

use*_*743 9

找到解决方案,如http://forum.spring.io/forum/spring-projects/data/114271-spring-data-jpa-modifying-query-failure中所述

"可以在批量HQL查询中指定隐式或显式的连接.子查询可以在where子句中使用,子查询本身可以包含连接."(Hibernate doc reference: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();
Run Code Online (Sandbox Code Playgroud)

  • 两个链接都失效了;c (3认同)