After setting up Hibernate you can start replicating objects. First you need to configure Hibernate to support the replication system. Additionally you need to enable UUIDs and version numbers on the db4o side.
Configuration hibernateConfig = new Configuration().configure("com/db4odoc/drs/rdms/hibernate.cfg.xml"); ReplicationConfigurator.configure(hibernateConfig);
configuration.file().generateUUIDs(ConfigScope.GLOBALLY);
configuration.file().generateCommitTimestamps(true);
After configuring Hibernate and db4o, the system is ready for replication. Like the db4o to db4o replication you start by creating a replication-session.
ObjectContainer container = openDB(); Db4oEmbeddedReplicationProvider providerA = new Db4oEmbeddedReplicationProvider(container); HibernateReplicationProvider providerB = new HibernateReplicationProvider(hibernateConfig); ReplicationSession replicationSession = Replication.begin(providerA, providerB); replicationSession.setDirection(replicationSession.providerA(),replicationSession.providerB());
After that you can request for the changed objects and replicate object by object to Hibernate:
final ObjectSet changesInHibernate = replicationSession.providerA().objectsChangedSinceLastReplication(); for (Object changedObject : changesInHibernate) { replicationSession.replicate(changedObject); } replicationSession.commit();