This one time, at band camp, David Tam said:

DT>just want to know the meaning of 'depends'.
DT>
DT>i have the following mapping:
DT>
DT>/*********************************************************/
DT><mapping>
DT> <class name="og_User" access="shared" identity="userId statInd" >
DT>  <description>just a testing mapping for trying out castor</description>
DT>  <cache-type type="count-limited" capacity="30"/>
DT>  <map-to table="OGT_USER" />
DT>  <field name="userId" type="string" required="true">
DT>   <sql name="USER_ID" type="varchar" />
DT>  </field>
DT>  <field name="userNam" type="string" >
DT>   <sql name="USER_NAM" type="varchar" />
DT>  </field>
DT>  <field name="userBrokerMaps" type="og_UserBrokerMap" collection="collection"
DT>lazy="false"
DT>  set-method="setUserBrokerMaps" get-method="getUserBrokerMaps">
DT>  <sql many-table="OGT_USER_BKR_MAP"/>
DT>  </field>
DT> </class>
DT> <class name="og_UserBrokerMap" depends="og_User" identity="userId" >
DT>  <description>just a testing mapping for trying out castor</description>
DT>  <cache-type type="count-limited" capacity="30"/>
DT>  <map-to table="OGT_USER_BKR_MAP" />
DT>  <field name="userId" type="string" required="true">
DT>   <sql name="USER_ID" type="varchar" />
DT>  </field>
DT>  <field name="statInd" type="char">
DT>   <sql name="STAT_IND" type="varchar" />
DT>  </field>
DT>  <field name="Broker" type="og_Broker" >
DT>   <sql name="BKR_CDE" />
DT>  </field>
DT></mapping>
DT>/*********************************************************/
DT>
DT>and the following code:
DT>
DT>
DT>/*********************************************************/
DT>
DT>db = myJDO.instance().getDatabase();
DT>
DT>// Construct a new query and bind the id value
DT>db.begin();
DT>
DT>//create a new BrokerMap
DT>og_UserBrokerMap om = new og_UserBrokerMap();
DT>om.setUserId("90000009");
DT>om.setStatInd('A');
DT>
DT>//create a new user
DT>og_User ou = new og_User();
DT>ou.setStatInd('A');
DT>ou.setUserId("90000009");
DT>ou.setUserNam("castor test insert object og_User");
DT>
DT>db.create(ou);
DT>//db.create(om);
DT>//db.create(ob);
DT>
DT>Collection vtr = new Vector();
DT>vtr.add(om);
DT>ou.setUserBrokerMaps((Collection)vtr);
DT>
DT>db.commit();
DT>db.close();
DT>
DT>/*********************************************************/
DT>
DT>what i would expect id when the commit() is called, both class(master object and
DT>dependent object) will be save to the database.  but in my test it seems that
DT>only the master object is saved to the database.
DT>call anyone clarify on this or tell me what i have done wrong?

Dave,

For the description of the depends keyword, please see here:

    http://castor.exolab.org/castor-one.html#Dependent-and-related-relationships

As far as your code is concerned, there is no bi-directional relation
set up between og_UserBrokerMap and og_User. Castor currently only
supports bi-directional relationships between objects. Implement a
reference from og_User to og_UserBrokerMap. Then upon performing a
db.create() for the instance of og_UserBrokerMap, the instance of
og_User.

A good example of the use of depends is provided in the examples.
Please see src/examples/jdo/mapping.xml and src/examples/myapp.
Notice that ProductDetail depends upon Product.

Bruce
--

perl -e 'print unpack("u30","<0G)U8V4\@4VYY9&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to