Hi all,
Let's say I have a parent entity that has children entities, and I enable cascading. If I change one of the children and save the parent, then the child will be persisted, because of the cascade mechanism. All is well. However, Hibernate does not update the time-stamp (or version) column of the parent object - only the child's time-stamp is updated.
This is reasonable, since the child was the only one changed, but this makes it difficult for me to apply optimistic locking on the hierarchy as a whole.
Here's an example: if the application has an "edit X" screen, that allows changing the parent and/or its children, and user A and user B both load the same parent and work on it, then if user A changes a property of a child and saves, and afterwards user B changes a property of the parent and saves, then user B will succeed, although I would have preferred he failed, since the parent is stale as far as I'm concerned: a change anywhere down the graph, should count as a change. Or, shouldn't it?
I'd be interested in hearing opinions about this, and whether anyone has dealt with such a requirement, using a Hibernate feature, or some customized solution.
Thanks,
Naaman
|