I tried autocreating mapping file for a simple example using MappingTool to
maybe give a hint on how to do this:
public class Owner {
private String name;
private ArrayList<Vehicle> vehicles = new ArrayList<Vehicle>();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<Vehicle> getVehicles() {
return vehicles;
}
public void setVehicles(ArrayList<Vehicle> vehicles) {
this.vehicles = vehicles;
}
}
public class Vehicle {
private String name;
private Owner owner;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Owner getOwner() {
return owner;
}
public void setOwner(Owner owner) {
this.owner = owner;
}
}
MappingTool tool = new MappingTool();
tool.setInternalContext(new BackwardCompatibilityContext());
boolean deep = true;
File targetFile = new File("generated-mapping.xml");
log.debug("generating mapping file...");
tool.addClass(Owner.class, deep);
fw = new FileWriter(targetFile);
tool.write(fw);
log.debug("...done generating mapping file: " + targetFile);
But the end result is:
<?xml version="1.0" encoding="UTF-8"?>
<mapping xmlns="http://castor.exolab.org/"
xmlns:cst="http://castor.exolab.org/">
<description xmlns="">Castor generated mapping file</description>
<class name="tests.Owner">
<description xmlns="">Default mapping for class
tests.Owner</description>
<map-to/>
<field name="name" type="java.lang.String">
<bind-xml name="name" node="element"/>
</field>
<field name="vehicles" type="java.lang.Object"
collection="arraylist">
<bind-xml name="vehicles" node="element"/>
</field>
</class>
</mapping>
So it seems it maps Vehicles in the list as Objects, which does not help
--
View this message in context:
http://old.nabble.com/How-to-map-cyclic---recursive-objects--tp26317185p26320291.html
Sent from the Castor - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email