-1

How to reattach an object to a detached session and also override the equals and hash code methods ?

This overriding is to confirm whether it is the same object that is attached back to session ?

perror
  • 7,071
  • 16
  • 58
  • 85

1 Answers1

0

I think that merge is the proper way to reattach objects. The Hibernate API for Session.merge(obj) states the following

Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy of and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped with cascade="merge".

Sebri Zouhaier
  • 745
  • 7
  • 18