I’m currently migrating old client-server application to hibernate, and would like to get some advice as to best way to implement following workflow.
Suppose we have a Contract entity, which refers to several Participant entity, among others. In current 2-tier application client starts a transaction with some row in contract table, modifies it during multiple requests and then either decides to commit a transaction or cancel (rollback).
During this long-running multi-request transaction client may several times open a sub-form, to edit particular Participant. This sub-form must follow the same logic – client make some changes to participant and can either confirm those or discard. In 2-tier application this logic is implemented via savepoints – before opening participant sub-form client creates a savepoint and if user chooses to discard current changes when closing a sub-form, server performs rollback to savepoint.
Now, in real application both Contract and Participant are highly complex entities, Contract row may directly or indirectly refer to hundreds of other tables, and Participant row – to dozens of other tables.
So, currently I’m attempting to implement this with hibernate in the following way
I have two instances of extended EntityManager, one for contract form, one for participant sub-form. Contract EM loads contract entity and persists it, when user asks an application to save all changes in main contract form
When user opens a Participant sub-form, selected or new participant entity is merged into Participant EM, and sub-form deals with this merged-managed-by-participant-EM participant entity
If user chooses to confirm his changes, then participant entity is merged back into contract EM.
The problem I’ve encountered with this setup is that after upgrading hibernate from 6.2.7.Final to 6.6.7.Final this workflow started to throw StaleObjectStateException (due to fix for HHH-1661)
What is proper way to implement such workflow, when changing temporary state may need to be reverted not to its original state, but to some “savepoint”?
Thanks in advance for any advice, suggestions, pointers