You are here: Replication With RDBMS > Replicate From db4o To Hibernate

Replicate From db4o To Hibernate

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);
Db4oRDBMSReplicationExamples.java: Prepare the Hibernate configuration
configuration.file().generateUUIDs(ConfigScope.GLOBALLY);
configuration.file().generateCommitTimestamps(true);
Db4oRDBMSReplicationExamples.java: Configure db4o to generate UUIDs and commit timestamps

Start The Replication

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());
Db4oRDBMSReplicationExamples.java: Prepare replication

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();
Db4oRDBMSReplicationExamples.java: Replicate from db4o to Hibernate