What is dynamic-update ?
The dynamic-update attribute tells Hibernate whether to include unmodified properties in the SQL UPDATE statement.
Dynamic-update example
The dynamic-update attribute tells Hibernate whether to include unmodified properties in the SQL UPDATE statement.
Dynamic-update example
1. dynamic-update=false
The default value of dynamic-update is false, which means include unmodified properties in the Hibernate’s SQL update statement.
For example, get an object and try modify its value and update it.
Hibernate will generate the following update SQL statement.
Hibernate will update all the unmodified columns.
2. dynamic-update=true
If set the dynamic-insert to true, which means exclude unmodified properties in the Hibernate’s SQL update statement.
For example, get an object and try modify its value and update it again.
Hibernate will generate different update SQL statement.
Hibernate will update the modified columns only.
Performance issue
In a large table with many columns (legacy design) or contains large data volumes, update some unmodified columns are absolutely unnecessary and great impact on the system performance.
In a large table with many columns (legacy design) or contains large data volumes, update some unmodified columns are absolutely unnecessary and great impact on the system performance.
How to configure it
You can configure “
dynamic-update
” properties via annotation or XML mapping file.1. Annotation
2. XML mapping
Conclusion
This little “dynamic-update” tweak will definitely increase your system performance, and highly recommended to do it.
No comments:
Post a Comment