Is there a way for updating only some fields of an entity object using the method save
from Spring Data JPA?
For examp
You are able to write something like
@Modifying
@Query("update StudentXGroup iSxG set iSxG.deleteStatute = 1 where iSxG.groupId = ?1")
Integer deleteStudnetsFromDeltedGroup(Integer groupId);
Or If you want to update only the fields that were modified you can use annotation
@DynamicUpdate
Code example:
@Entity
@Table(name = "lesson", schema = "oma")
@Where(clause = "delete_statute = 0")
@DynamicUpdate
@SQLDelete(sql = "update oma.lesson set delete_statute = 1, "
+ "delete_date = CURRENT_TIMESTAMP, "
+ "delete_user = '@currentUser' "
+ "where lesson_id = ?")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})