{"id":281,"date":"2024-03-05T18:55:14","date_gmt":"2024-03-05T17:55:14","guid":{"rendered":"https:\/\/fixthebugs.com\/?p=281"},"modified":"2024-03-05T18:55:15","modified_gmt":"2024-03-05T17:55:15","slug":"update-multiple-fields-with-jpa-query","status":"publish","type":"post","link":"https:\/\/fixthebugs.com\/index.php\/2024\/03\/05\/update-multiple-fields-with-jpa-query\/","title":{"rendered":"Update multiple fields with JPA query"},"content":{"rendered":"\n<p>To update multiple fields in DB with JPA you have to use <strong>@Modifying and @Query<\/strong>. Here, an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Repository\npublic interface CarRepository extends JpaRepository&lt;CarDto, String> {\n\n     \/\/Here we update fields color and brand dynamically using parameters\n     @Modifying\n     @Query(\"update CarDto c set c.color = :color, c.brand = :brand where c.numberOfDoors = 5\")\n     void updateColorAndBrand(@Param(\"color\") String color, @Param(\"brand\") String brand);\n\n}<\/code><\/pre>\n\n\n\n<p>For more interesting tutorials &amp; guides just check them&nbsp;<a rel=\"dofollow\" href=\"https:\/\/fixthebugs.com\/index.php\/category\/tutorials-guides\/\">HERE<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To update multiple fields in DB with JPA you have to use @Modifying and @Query. Here, an example: For more interesting tutorials &amp; guides just check them&nbsp;HERE.<\/p>\n","protected":false},"author":1,"featured_media":283,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[10],"tags":[102,103,72,101],"_links":{"self":[{"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/posts\/281"}],"collection":[{"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/comments?post=281"}],"version-history":[{"count":3,"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/posts\/281\/revisions"}],"predecessor-version":[{"id":287,"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/posts\/281\/revisions\/287"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/media\/283"}],"wp:attachment":[{"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/media?parent=281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/categories?post=281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fixthebugs.com\/index.php\/wp-json\/wp\/v2\/tags?post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}