The entity 'Ticket' has a collection 'Lines'. I use optimistic locking and access the entity from different instances of the application and must make sure that each instance reliably gets the most recent version of both 'Ticket' and 'Lines'.
I've set
Code:
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE
(and also tried ALL), and it works as expected when I either
- delete an element from the collection or
- add an element to the collection
and then save the related 'Ticket'. Version numbers of both Ticket and Lines get incremented.
If I update an existing collection item and then save the related 'Ticket' the Lines version is incremented, but the Tickets version is not and another instance will not recognize that the Lines collection has changed.
I'm banging my head about this behaviour. Am I missing something?
I could possibly introduce an updated_at property for 'Ticket' and set it to the current timestamp to force 'Ticket' to be dirty but I can't believe that this should be necessary.
Any advise is very much appreciated.