The most likely explanation is due to proxying. When you save REC_NEW, its collection is put into the session cache. Because you retrieved REC1 from the same session, this means that its collection is the same one, and therefore is updated with the new values. This is the way hibernate is designed. To continue to use your current design, you must detach REC1 before modifying REC_NEW (session.evict(REC1)). A better approach, if it's possible, is to use only REC1, removing the need for REC_NEW. And if there's an error in your application, roll back the transaction.
|