I am loading some hibernate objects through hibernate search and then showing them in the UI. There, our user selects one object and removes some elements from a @ManyToMany association.
Of course, as written in the hibernate documentation when the session is flushed, changes are persisted automatically even if I don’t call Session#save in the object found.
But that is not the behavior I need. I need my user to remove the objects from the association but only temporally, only for making a report from the modified object without changing my database. So the removed objects in the association do not show in my report.
How can I make this happen?
I was thinking in mark the associated objects as Cloneable and build a new entity and make changes there as all the operation in this particular UI are read-only.
Any suggestions?
Mark the collection with
cascade="evict". Then remove the objects as you like, generate your report, thenevict()the object before flushing.