Hibernate Replication Internals

This topic applies to Java version only 

So far we have seen that dRS allows you to replicate objects between db4o and relational database. You maybe curious about how dRS keeps track of the identity of objects in relational database and how dRS knows which objects are changed since the last round of replication. Read on and you will see how dRS does that.

dRS internal objects keep information used by replication. Each internal object is associated with a Hibernate mapping file (.hbm.xml). Hibernate reads these files and understands  how to store / retrieve these internal objects to / from the RDBMS. Each type of internal object maps to one table in RDBMS. If such table does not exist, Hibernate creates it automatically.

ProviderSignature, MySignature and PeerSignature

ProviderSignature uniquely identifies a ReplicationProvider. MySignature and PeerSignature are the subclasses of ProviderSignature. A HibernateReplicationProvider has a MySignature to serve as its own identity. PeerSignature identifies the peer ReplicationProvider during a ReplicationSession.

Record

Record contains the version of the RDBMS during a ReplicationSession. Near the end of a ReplicationSession, two ReplicationProviders synchronize their versions.

Record allows dRS to detect changed objects. dRS detects changed objects by comparing the version of an object (v) with the maximum version of all Records (m). An object is updated if v > m.

UUID

UUID uniquely identifies a persisted object in dRS.
Each persisted object is identified by a "typed_id" in Hibernate. This "typed_id" is unique only with its type of that object (i.e. A car has an "typed_id" of 1534, a Pilot can also has an "typed_id" of 1534) and within the current RDBMS.
How do we identify "a Pilot that is originated from Oracle instance pi2763" ? To do so, we need two parameters:
   1. an id that is unique across types
   2. association between this id and the ProviderSignature of the RDBMS (The RDBMS that owns this object)

class UUID {
    long longPart;
    ProviderSignature provider;
}

Collectively, 1 and 2 forms the "UUID".

ObjectReference

ObjectReference contains the UUID and the version of a persisted object. It also contains the className and the typed_id of that persisted object.
UUID forms an 1 to 1 relationship with {className, typedId}.

class ObjectReference {
    String className;
    long typedId;
    Uuid uuid;
    long version;
}

List of dRS tables

drs_providers

 Column TypeFunction
  id  long  synthetic, auto-increment primary key
  is_my_sig char(1)  't' if MySignature, 'f' if PeerSignature
  signature binary  holds the unique identifier - byte array
  created  long  legacy field used by pre-dRS db4o replication code

drs_history

 Column
Type
Function
  provider_id  long primary key, same as the PK of a PeerSignature
  time long the version of the RDBMS during a ReplicationSession

drs_objects


Column Type
Function
id long synthetic, auto-increment primary key
created long the UUID long part of this ObjectReference
provider_id long specifies the originating ReplicationProvider of this ObjectReference
class_name varchar the type of the referenced object
typed_id long the id used by Hibernate, which is only unique within its type
modified
 long the version of the referenced object