title: Hibernate Save Object to Multiple Sessions
body: <p>I am attempting to write to multiple databases using hibernate.  I have encapsulated write and read/write sessions within a single session object.  However, when I go to save I get a lot of errors that the objects are already associated with another session: "Illegal attempt to associate a collection with two open sessions"</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class MultiSessionObject implements Session {
  
         private Session writeOnlySession;
         private Session readWriteSession;
  
         @Override
         public void saveOrUpdate(Object arg0) throws HibernateException {
                readWriteSession.saveOrUpdate(arg0);
                writeOnlySession.saveOrUpdate(arg0);
         }
  }
  </code></pre>
  
  <p>I have tried evicting the object and flushing; however, that causes problems with "Row was updated or deleted by another transaction"... even though both sessions point to different databases.</p>
  
  <pre><code>public class MultiSessionObject implements Session {
  
         private Session writeOnlySession;
         private Session readWriteSession;
  
         @Override
         public void saveOrUpdate(Object arg0) throws HibernateException {
                readWriteSession.saveOrUpdate(arg0);
                readWriteSession.flush();
                readWriteSession.evict(arg0);
  
                writeOnlySession.saveOrUpdate(arg0);
                writeOnlySession.flush();
                writeOnlySession.evict(arg0);
         }
  }
  </code></pre>
  
  <p>In addition to the above, I have also attempted using the replicate functionality of hibernate.  This was also unsuccessful without errors.</p>
  
  <p>Has anyone successfully saved an object to two databases that have the same schema?</p>