Robin Hoogeboom wrote:
I'm trying to create records in my database with Castor JDO. I want to save a master record with an keygenerator and a sub having this generated id as a 1-n reference.Can this be done ? and if so, how ? I've tried the following option: db=_jdo_.getDatabase(); db.setAutoStore(true); db.begin(); db.create(master);
The master object is not yet created, creation is delayed until commit. => this line will not work
master.getSub(0).setMasterID(master.getID);
db.commit();
Mapping file <snippet>:
<class name="Master" identity="ID" access="shared" key-
generator="MASTERID">
<cache-type type="none"/>
<map-to table="master"/>
<field name="ID" type="java.lang.Integer"><sql name="masterid" type="integer"/></field>
<field name="Sub" type="Sub" collection="vector"><sql many-
key="masterid" dirty="check" /></field>
</class>
<class name="Sub" identity="ID" access="shared" key-
generator="SUBID">
<cache-type type="none"/>
<map-to table="sub"/>
<field name="ID" type="java.lang.Integer"><sql name="subid" type="integer"/></field>
<field name="masterID" type="java.lang.Integer"><sql name="masterid" type="integer"/></field>
</class>
You should have a master attribute of type Master in you sub class, not directly the masterID.
Do i need an depends in my mapping file ? Is there some (other) solution or informationYou could, but this is not mandatory.
on this.
Have a look at the DependentOrder test for an example of a simple
one to many mapping.
--
Mickael Guessant
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
