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?