Hi,
I'm currently thinking about strategies for merging object areas in a object graph in a 3-tier environment (third tier may not have Hibernate dependencies; areas are connected by hibernate cascade all). From my point of view, there are three different merge strategies:
- Reattach the cascade root with saveOrUpdate - works in every case but with worst performance (writing all the objects each time).
- Reattach the cascade root with merge - works fine if the domain model and cascading is implemented well. merge() reads every object from database and writes only the detected changes. So it should perform better in comparison to saveOrUpdate, mentioned above.
- Reattach 'manually' without hibernate cascading support - reattach every object 'manually' using plain lock/save/update. A possible way to implement this strategy, is to use a changed flag, demarked by class and ID and use a visitor pattern with save-, delete- and detach- and reattach-visitors. I would expect the best performance here.
My questions are,
- is there an additional merge strategy anywhere out there?
- what's your experience using the above merge strategies?
Best regards,
Micha