java - Spring Data JPA, hibernate: update all query and SET value by selecting from another table -


is following sql possible in jpa query? tried actual sql hibernate runs doesn't seem right.

this sql want write jpa query;

update movie m set average_rating = coalesce((select avg(stars) rating r r.movie_id = m.id), 0); 

this jpa query;

@query("update movie m set m.averagerating = coalesce((select avg(r.stars) rating r r.movie = m), 0)") 

and hibernate says;

hibernate:     insert             ht_movie         select             movie0_.id id                     movie movie0_ hibernate:     update         movie     set         average_rating=coalesce((select             avg(rating1_.stars)                     rating rating1_                     rating1_.movie_id=id),         0)             (             id         ) in (             select                 id                             ht_movie         ) 

so there seems additional being added hibernate.

@query("update movie m set m.averagerating = coalesce((select avg(r.stars) rating r r.movie = m), 0)") 

this 100% correct. , hibernate works correctly well. hibernate works in way:

  1. create temporary table ht_movie , insert ids of movie table.
  2. create jpa query whole where
  3. compare abstracting ids ht_movie t enforce more speed in update processing

and not new hibernate fabricates queries.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -