2

I am just curious when to use merge() method before saving an object in hibernate. I saw an example that uses merge() before saving with an object that has a many to many relationship with another object.

Example for using merge: Role has ManyToMany with Permission and it sets List of Permission in the Role object before saving.

So is that's only that case, when the saved object has relation with other objects?

I need good explanation and use cases.

acdcjunior
  • 132,397
  • 37
  • 331
  • 304
fresh_dev
  • 6,694
  • 23
  • 67
  • 95

1 Answers1

1

Hibernte merge method will force Hibernate to copy any changes from other detached instances onto the instance you want to save, and thus merges all the changes in memory before the save.

Please refer to these posts below with details on the differences and examples..

Different methods

This has more detailed explanation with an example

Hope this helps.

Community
  • 1
  • 1
Prashanth
  • 1,388
  • 2
  • 11
  • 26