Reputation: 2455
In hibernate, we can update entities in DB by many different ways. If we change attached entity in opened session, and then commit changes(by closing session), all changes will be saved in DB. But, for example, particular entity has many fields. And we want to change only couple of them. Then, hibernate will generate query, where it will update all fields of entity: changed and unchanged. Therefore, there is overhead in hibernate generated update query. If we know, which fields of object will be changed, would it be better to create navite SQL query, where we can update only specified fields? What props and cons?
Upvotes: 0
Views: 791
Reputation: 242686
You can configure Hibernate to update only changed fields as follows:
@org.hibernate.annotations.Entity(dynamicUpdate = true)
However, the actual effect of this setting should be carefully tested, because in some cases it can decrease performance.
See also:
Upvotes: 1