First you need to add Hibernate. Read the Hibernate documentation to configure Hibernate properly. This reference documentation only shows the essentials to get started.
In order to replicate against Hibernate you need to add the Hibernate jars. The dRS distribution contains a copy of Hibernate. dRS is only tested against that Hibernate version. You need to add following dependencies to your project.
Hibernate needs some configuration. You need to configure the database-driver, the database-connection and the SQL dialect. Read more on the official Hibernate documentation.
<hibernate-configuration> <session-factory> <!-- Specify the database driver --> <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property> <!-- The JDBC connection string --> <property name="hibernate.connection.url">jdbc:hsqldb:mem:database.hsql</property> <!-- User name an password for the database --> <property name="hibernate.connection.username">sa</property> <property name="hibernate.connection.password"></property> <!-- Specify the SQl-dialect --> <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property> <property name="hibernate.show_sql">true</property> <!-- Update the database schema if out of date --> <property name="hibernate.hbm2ddl.auto">update</property> <!-- Add the mapping files for your classes --> <mapping resource="com/db4odoc/drs/rdms/Car.cfg.xml"/> <mapping resource="com/db4odoc/drs/rdms/Pilot.cfg.xml"/> </session-factory> </hibernate-configuration>
In order to store objects in Hibernate, you need define the mapping between the tables and the objects you store. There's only one requirement for the db4o replication: Each object needs a long field for the id. This id is used by dRS to recognize the object. For example we map the Pilot class to the pilots tables. Read more on the official Hibernate documentation.
<hibernate-mapping default-access="field" default-lazy="false" default-cascade="save-update"> <class name="com.db4odoc.drs.rdms.Pilot" table="pilots"> <id column="typed_id" type="long"> <generator class="native"/> </id> <property name="name"/> <property name="points"/> </class> </hibernate-mapping>