@org.hibernate.annotations.Entity(
dynamicInsert=true, dynamicUpdate=true
)
The dynamicInsert property is really only necessary to prevent writing NULL values to database fields. But if the changes involve setting NULL values (bad practice), you should probably turn it off.I can think of three possible implementations for dirty checking:
- Caching a clean copy of the record and maintaining an edit copy of the persistent object. When an SQL update is due, the copies are compared and changes extracted from the edit copy for update. Obviously memory-intensive as 2 copies of a record are maintained at all times.
- Keeping track of which fields changed.
- Doing a SQL query just before updating and doing the necessary reductions to determine what changed.