Take the 2-minute tour ×

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Mark the collection with cascade="evict". Then remove the objects as you like, generate your report, then evict() the object before flushing.

share|improve this answer
Just a note, I am using hibernate 3.6 so is CascadeType.DETACH instead of Evict. –  ElderMael Jul 11 '12 at 19:36
add comment

Your Answer


