This topic applies to Java version only
Similar to array, you can repliate a List of Cars.
1package f1.collection.list; 2
3
import java.util.List; 4
5
public class Pilot { 6
String name; 7
List cars; 8
}
Map the List using the list tag in Pilot.hbm.xml
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.list.Pilot"> 09
<id column="typed_id" type="long"> 10
<generator class="native"/> 11
</id> 12
13
<property name="name"/> 14
15
<list name="cars" table="cars"> 16
<key column="pilotId"/> 17
<list-index column="sortOrder"/> 18
<one-to-many class="f1.collection.Car"/> 19
</list> 20
</class> 21
</hibernate-mapping>
Replicate the pilot:
01public class ListExample { 02
public static void main(String[] args) { 03
new File("ListExample.yap").delete(); 04
05
System.out.println("Running List example."); 06
07
ExtDb4o.configure().generateUUIDs(Integer.MAX_VALUE); 08
ExtDb4o.configure().generateVersionNumbers(Integer.MAX_VALUE); 09
10
ObjectContainer objectContainer = Db4o.openFile("ListExample.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 ArrayList(); 24
pilot.cars.add(car1); 25
pilot.cars.add(car2); 26
27
objectContainer.set(pilot); 28
objectContainer.commit(); 29
30
Configuration config = new Configuration().configure("f1/collection/list/hibernate.cfg.xml"); 31
32
ReplicationSession replication = HibernateReplication.begin(objectContainer, config); 33
34
ObjectSet changed = replication.providerA().objectsChangedSinceLastReplication(); 35
36
while (changed.hasNext()) 37
replication.replicate(changed.next()); 38
39
replication.commit(); 40
replication.close(); 41
objectContainer.close(); 42
43
new File("ListExample.yap").delete(); 44
}