2016-11-23 34 views
2

我想用spring data rest来更新某些用户的行,但是在运行时这个查询有奇怪的“交叉连接”添加到查询中。创建spring data rest update产生交叉连接sql错误

春天数据休息方法

@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控制器,两种方式产生相同的错误

在此先感谢。

+0

我们看一些实体的代码片段 – Blank

回答

2

http://forum.spring.io/forum/spring-projects/data/114271-spring-data-jpa-modifying-query-failure表示实测值溶液

“没有连接,隐式或显式的,可在大批量HQL语句进行指定。子查询可以在WHERE子句,其中所述子查询本身可以包含在使用连接“(休眠DOC参考: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(); 
+0

这仅适用于DML风格的操作。 – Alex78191