Hello any one suggest me that when to use merge() instead of save()?
I have some issue like when I save domain with save() method it's working fine in some case but in some case it's creating "org.hibernate.LazyInitializationException"
exception for me.
Can I use direct merge() method to save domain instance instead of save()?
You can see that both merge()
and save()
methods calling save()
method internally, the difference is in their behavior i.e If you store object in HTTP session and later want to access that but this object has lost its persistent context, the merge() method merge's a detached object's state back into the current Hibernate session.But if you called the save() method on detached object's you will face a sexy exception(org.hibernate.LazyInitializationException
) as mentioned by you.
For further info documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With