2016-11-23 68 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