-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Save Object to Multiple Sessions
PostPosted: Wed Apr 08, 2015 1:52 pm 
Newbie

Joined: Wed Apr 08, 2015 1:50 pm
Posts: 1
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"

Here is my code:

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);
       }
}


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.
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);
       }
}


In addition to the above, I have also attempted using the replicate functionality of hibernate. This was also unsuccessful without errors.

Has anyone successfully saved an object to two databases that have the same schema?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.