How to use Spring Data JPA Repository for update query between 2 tables? -


i have 2 tables abc , xyz , deviceid(pk in abc) serves foreign key. how can use spring data jpa repo methods, in way - updatedevicetype(which in abc table), if want update query below,

abcrepository

@modifying @query(name = "updatedevicetype", value = "update abc abc,xyz xyz set abc.devicetype = ?1 abc.deviceid = xyz.deviceid.deviceid , xyz.deviceid.deviceid= ?2") 

the error comes caused by: org.hibernate.hql.internal.ast.querysyntaxexception: expecting "set", found ',' near line 1, column 45

your jpql update query seems incorrect. did not post abc , xyz classes, can quess going simillar following:

update abc abc  set abc.devicetype = ?1       exists (         select 1         xyz xyz                       abc.deviceid = xyz.deviceid.deviceid              , xyz.deviceid.deviceid= ?2     ) 

that complex query , suggest creating named query out of it, , not holding in @query annotation.

side note: should remember there option of using native queries in jpa , spring data jpa if going deploy single type of database , offers nicer update syntax.


Comments