-->
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.  [ 2 posts ] 
Author Message
 Post subject: Replicate between two databases
PostPosted: Tue Jun 08, 2004 6:06 am 
Newbie

Joined: Tue Jun 08, 2004 5:45 am
Posts: 2
Hi,

My Hibernate App includes functionality to "synchronize" data between two databases (one for development and production). I'm trying to use Hibernate to copy/update data, but I'm crashing again and again. Should I use plain SQL to INSERT / UPDATE data on my production DB?

All my objects have to use "assigned" for generator class, because when I'm copying the objects I need to retain the actual object ID (for future updates), so the object has an ID and should be INSERTed on the production database.

I think I should use something like that:

Code:
  Session devSess = getDevelopmentSession();
  Session productionSession = getProductionSession();

  Iterator it = devSess.createQuery ("the query").iterat();
  while (it.hasNext()) {
     MyObject obj = it.next();
     devSess.evict (obj);
     if (isExistingObject (productionSession)) {
         productionSession.save (obj);
     }
     else {
         productionSession.update (obj);
     }
  }


If it's a new object, everything go OK, ** but **, when the object exists on the production DB, the code fails with "NonUniqueObjectException".

I think that, since I'm calling "update()" (and not save()), the object indeed exists!!! What I'm missing??

I've tried everything: saveOrUpdateCopy(), replicate(), creating a new transient object using a "copy constructor"... allways the same NonUniqueObjectException.

Any ideas? Is there a method (a mean a way) to do this? Should I implement an Interceptor? A Persister?? Should I use plain SQL or other "data base specific tools"?

I'm using Hibernate 2.1.3. My development database is an Oracle 8.1.7, and my production database is an Oracle 9i

Thanks in advance for any kind of help,

Gustavo Comba


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 10:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use replicate()


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

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.