-->
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.  [ 4 posts ] 
Author Message
 Post subject: Copying data from one DB to another
PostPosted: Wed May 04, 2005 3:50 am 
Newbie

Joined: Wed May 04, 2005 3:33 am
Posts: 6
Hibernate version: 2.1.7

Hello,
I am trying to sycronizes Data between one Database and a other using Hibernate. I am doing this with session replicate. Here is the source code

Code:
public boolean syncronize(Class hibernateClass, Session from, Session to) throws HibernateException
    {
            Transaction trans = to.beginTransaction();
            List newData = from.createCriteria(hibernateClass).list();
            for (Iterator iter = newData.iterator(); iter.hasNext();)
            {
                Object element = (Object) iter.next();
                to.replicate(element,ReplicationMode.OVERWRITE);
            }
            trans.commit();
     } 


This works fine for objects that have no associations at all, but for all other objects following exception is thrown
Code:
net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
   at net.sf.hibernate.collection.PersistentCollection.setCurrentSession(PersistentCollection.java:257)
   at net.sf.hibernate.impl.OnReplicateVisitor.processCollection(OnReplicateVisitor.java:37)
   at net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
   at net.sf.hibernate.impl.AbstractVisitor.processValues(AbstractVisitor.java:36)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:925)
   at net.sf.hibernate.impl.SessionImpl.replicate(SessionImpl.java:3949)


I guess i am abusing the replication but is there another way?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 4:46 am 
Regular
Regular

Joined: Tue Nov 23, 2004 7:42 am
Posts: 82
Location: London, England
What happens when you try this?
Code:
for (Iterator iter = newData.iterator(); iter.hasNext();)
{
    Object element = (Object) iter.next();
    from.evict(element);
    to.replicate(element,ReplicationMode.OVERWRITE);
}


Top
 Profile  
 
 Post subject: Re: Copying data from one DB to another
PostPosted: Wed May 04, 2005 4:55 am 
Beginner
Beginner

Joined: Thu May 13, 2004 5:51 am
Posts: 28
Herbert.Fresacher wrote:
Hibernate version: 2.1.7

Hello,
I am trying to sycronizes Data between one Database and a other using Hibernate. I am doing this with session replicate.

I guess i am abusing the replication but is there another way?


Is the database of the same type? as in, is the migration from MySQL to another MySQL? If yes, then u might want to use native support from the database, that ensures all your sequences and other non explicit table data gets migrated seamlessly.

If the databases are of different type, u might want to try dbunit.

--
Meg


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 5:43 am 
Newbie

Joined: Wed May 04, 2005 3:33 am
Posts: 6
Thanx Rilux .... evict worked fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.