spring数据休息更新产生交叉连接sql错误 [英] spring data rest update produce cross join sql error

查看:13
本文介绍了spring数据休息更新产生交叉连接sql错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to use spring data rest to update rows of certain user , but at run time this query has strange "cross join" added to the query .

spring 数据休息方法

spring data rest method

 @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 错误

My only concern is why "cross join" added as it gives sql error

org.postgresql.util.PSQLException: ERROR: syntax error at or near "cross"

我直接通过 rest invoke 调用这个方法,也从 mvc 控制器调用,两种方式都会产生相同的错误

I call this method directly by rest invoke , and also from mvc controller, both ways produce the same error

提前致谢.

推荐答案

找到 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-直接)."

"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 doc reference: http://docs.jboss.org/hibernate/core.../#batch-direct)."

所以我编辑了我的代码以使用子查询

So I edited my code to use sub query

@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数据休息更新产生交叉连接sql错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆