This topic applies to Java version only
Hibernate requires a xml configuration file (hibernate.cfg.xml) to run. In order to run dRS with Hibernate, the user has to set some parameters in the configuration file.
01<hibernate-configuration> <session-factory> 02
<!-- Database connection settings --> 03
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> 04
<property name="hibernate.connection.url">jdbc:oracle:thin:@ws-peterv:1521:websys</property> 05
<property name="hibernate.connection.username">db4o</property> 06
<property name="hibernate.connection.password">db4o</property> 07
<!-- JDBC connection pool (use the built-in) --> 08
<property name="hibernate.connection.pool_size">1</property> 09
<!-- SQL dialect --> 10
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property> 11
<!-- Echo all executed SQL to stdout --> 12
<property name="hibernate.show_sql">false</property> 13
<!-- Update the database schema if out of date --> 14
<property name="hibernate.hbm2ddl.auto">update</property> 15
16
<property name="hibernate.jdbc.batch_size">0</property> 17
</session-factory> 18
</hibernate-configuration>
For the property "hibernate.connection.pool_size", dRS requires only 1 connection to the RDBMS, increasing it will not have any effect. "hibernate.jdbc.batch_size" is set to 0 is for easier debugging. You may increase it to batch SQL statements to potentially increase performance.
It is a MUST that "hibernate.hbm2ddl.auto" be set to "update" because
the system will create some extra tables to store the metadata for
replication to work properly.
<property name="hibernate.hbm2ddl.auto">update</property>
In some situations, you may not have the privilege to create or alter tables. You may need to ask your DBA to create the tables for you before using dRS.
You can turn off the automatic creation of dRS tables and columns by changing the "hibernate.hbm2ddl.auto" property to "validate" in hibernate.cfg.xml. By doing so, dRS will not create or alter any tables. Rather, it will check the existence of the dRS tables before starting replication.
If the required dRS tables do not exist, dRS will throw a RuntimeException notifying the user and the replication will halt.
Persisted Objects are objects that the user wants to store to the database, e.g. cars, pilots, purchase orders.
For dRS to operate properly, for each persisted object, the user MUST
declare the primary key column of the database table in the hbm.xml
mapping file as follow:
<id column="typed_id" type="long">
<generator class="native"/>
</id>
- column - The name of the primary key column. The value can be well-formed string . "typed_id" is recommended.
- type - MUST be "long"
- class - MUST be "native"
The "typed_id" column stores the id used by Hibernate. It allows dRS to
identify a persisted object by invoking
org.hibernate.Session#getIdentifier(Object object).
If you do not define getter/setter for property, make
default-access="field". default-lazy="false" default-cascade="save-update" is required for replication to work
properly. Note, you should not set the cascade style to "delete",
otherwise deletion replication will not work.