I am using JPA with Hibernate. When I modify one attribute of an object and update it; the generated SQL shows all the columns getting updated ! Why doesn’t it update only the modified columns? Is there a way to achieve that because I feel that will be more optimized.
Share
By default hibernate includes all the fields in the update query. If you want to exclude this either use a custom update HQL or you can configure hibernate to exclude the unmodified fields in the update query as told in this article.
This is done by adding
dynamic-update="true"in your class mapping.In a large table with many columns (legacy design) or contains large data volumes, this will have a great impact on the system performance. It can have some performance impact as told here. So measure the performance of your code before you implement it.
Read the API here for more information.
If you are using annotations,
It is a hibernate specific annotation, and not available in JPA. Here is a good article linking to the details.