title: What is the proper way to re-attach detached objects in Hibernate?
body: <p>I have a situation in which I need to re-attach detached objects to a hibernate session, although an object of the same identity MAY already exist in the session, which will cause errors.</p>
  
  <p>Right now, I can do one of two things.</p>
  
  <ol>
  <li><p><code>getHibernateTemplate().update( obj )</code>
  This works if and only if an object doesn't already exist in the hibernate session. Exceptions are thrown stating an object with the given identifier already exists in the session when I need it later.</p></li>
  <li><p><code>getHibernateTemplate().merge( obj )</code>
  This works if and only if an object exists in the hibernate session. Exceptions are thrown when I need the object to be in a session later if I use this.</p></li>
  </ol>
  
  <p>Given these two scenarios, how can I generically attach sessions to objects? I don't want to use exceptions to control the flow of this problem's solution, as there must be a more elegant solution...</p>