Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring data rest update produce cross join sql error

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.

like image 740
user1021743 Avatar asked Nov 23 '16 02:11

user1021743


1 Answers

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();
like image 152
user1021743 Avatar answered Sep 21 '22 12:09

user1021743