So you're saying that when you do the merge operation I wouldn't be incurring overhead I'm already incurring with select-before-update?
We use ehcache but our Session open/closes all the time and I assume this rules on lazy fetching with ehcache. I'm curious as to why ehcache cannot reattach the object with the session.
mmerder wrote:
You could merge your root object before updating it. If you want all referenced objects to be merged, you can either set fetch-strategy to eager, or even better use CascadeType.MERGE, so that the merge-operation is cascaded to the relationship.
Maybe enabling batch-fetching is also a solution, but I am not sure in this case. To enable batch-fetching you have to enable it via hibernate-configuration (set
hibernate.jdbc.batch_size and
hibernate.default_batch_fetch_size).