This topic applies to Java version only
Hibernate version used with dRS supports one dimensional arrays but does not support multidimensional arrays.
1package f1.collection.array; 2
3
import f1.collection.Car; 4
5
public class Pilot { 6
String name; 7
Car[] cars; 8
}
01<?xml version="1.0"?> 02
03
<!DOCTYPE hibernate-mapping PUBLIC 04
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" 05
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 06
07
<hibernate-mapping default-access="field" default-lazy="false" default-cascade="save-update"> 08
<class name="f1.collection.array.Pilot"> 09
<id column="typed_id" type="long"> 10
<generator class="native"/> 11
</id> 12
13
<property name="name"/> 14
15
<array name="cars" table="cars"> 16
<key column="pilotId"/> 17
<list-index column="sortOrder"/> 18
<one-to-many class="f1.collection.Car"/> 19
</array> 20
</class> 21
</hibernate-mapping>
Add Pilot and Car to hibernate.cfg.xml
<mapping resource="f1/collection/array/Pilot.hbm.xml"/>
<mapping resource="f1/collection/Car.hbm.xml"/>
Save the pilot as usual and start replication:
01public class ArrayExample { 02
public static void main(String[] args) { 03
new File("ArrayExample.yap").delete(); 04
05
System.out.println("Running Array example."); 06
07
ExtDb4o.configure().generateUUIDs(Integer.MAX_VALUE); 08
ExtDb4o.configure().generateVersionNumbers(Integer.MAX_VALUE); 09
10
ObjectContainer objectContainer = Db4o.openFile("ArrayExample.yap"); 11
12
Pilot pilot = new Pilot(); 13
pilot.name = "John"; 14
15
Car car1 = new Car(); 16
car1.brand = "BMW"; 17
car1.model = "M3"; 18
19
Car car2 = new Car(); 20
car2.brand = "Mercedes Benz"; 21
car2.model = "S600SL"; 22
23
pilot.cars = new Car[]{car1, car2}; 24
25
objectContainer.set(pilot); 26
objectContainer.commit(); 27
28
Configuration config = new Configuration().configure("f1/collection/array/hibernate.cfg.xml"); 29
30
ReplicationSession replication = HibernateReplication.begin(objectContainer, config); 31
32
ObjectSet changed = replication.providerA().objectsChangedSinceLastReplication(); 33
34
while (changed.hasNext()) 35
replication.replicate(changed.next()); 36
37
replication.commit(); 38
replication.close(); 39
objectContainer.close(); 40
41
new File("ArrayExample.yap").delete(); 42
}