spring data rest update produce cross join sql error

笑着哭i 提交于 2019-12-10 16:06:57

问题


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 data rest method

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

run time created query

Hibernate: update notification cross join  set noticed=true where owner_id=?

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

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

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

Thanks in advance.


回答1:


Found solution as stated in http://forum.spring.io/forum/spring-projects/data/114271-spring-data-jpa-modifying-query-failure

"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();


来源:https://stackoverflow.com/questions/40755008/spring-data-rest-update-produce-cross-join-sql-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!