Yes, I also confirmed that it is the child one-to-many relationship that is the culprit. If I remove the lines mapping, everything works as expected. Unfortunately, I have
not made any progress on solving the problem and none of the "experts" have replied to my original post.
Further testing did also confirm that it is
not an issue of a detached/re-attached object graph. I confirmed this by adding a servlet filter that opens a session and puts it in thread local (a common pattern, I believe) so that all persistent object manipulation is using the same hibernate session. Still, I am seeing the parent object flush an update to the database even though no properties are being changed.
What is even more strange is that I introduced an entity interceptor to discover what properties hibernate thinks are dirty. Here is a snippet from my onFlushDirty method in the interceptor:
Code:
for (int i = 0; i < propertyNames.length; i++) {
if (previousState[i] != currentState[i]) {
log.debug("The state of property " + propertyNames[i] + " has changed [" + previousState[i] + " -> " + currentState[i] + "]");
}
}
Here is an excerpt from a log file related to the above code.
06:12:30,611 DEBUG HibernateAuditableInterceptor:178 - Logged update to com.mydomain.PurchaseOrder
06:12:30,611 DEBUG HibernateAuditableInterceptor:178 - The state of property version has changed [1 -> 1]
06:12:30,611 DEBUG HibernateAuditableInterceptor:178 - The state of property lineCount has changed [1 -> 1]
06:12:30,631 DEBUG HibernateAuditableInterceptor:178 - The state of property itemsCount has changed [5 -> 5]
06:12:30,681 DEBUG HibernateAuditableInterceptor:178 - The state of property updatedAt has changed [2005-12-12 20:27:57.0 -> 2005-12-12 20:27:57.0]
06:12:30,681 DEBUG HibernateAuditableInterceptor:178 - The state of property createdAt has changed [2005-12-12 20:27:41.0 -> 2005-12-12 20:27:41.0]
Why would the "state" of these properties be showing a change? Note that there are many more properties than just these so why would these properties show up as dirty? Remember, if I simply remove the version column mapping, then nothing gets flushed (unless, of course, it changes). Something is really weird here.....