Is it possible to persist an object as well as all of its
        childs in a single db.create(obj)? I'm not able to produce a
        mapping for that.

        This is my situation:

public Manufacturer {
  String manufacturerId;
  String manufacturerName;
  ArrayList manufacturerInfo;
  // getters, setters, empty constructor
}
public ManufacturerInfo {
  String manufacturerInfoId;
  Manufacturer manufacturer;
  Language language;
  String info;
  // getters, setters, empty constructor
}
public class Language {
  String languageId;
  String code;
  // getters, setters, empty constructor
}

        When loading Manufacturer by its ID, the complete hierarchy is
        created, with appropriate manufacturerInfo arraylist, which
        contains ManufacturerInfo object for related languages.

        But when trying to db.create(manufacturer), only manufacturer
        table is populated, there's no related rows in
        manufacturer_info table.

The client:

Manufacturer manufacturer = new ManufacturerImpl();
manufacturer.setName("some name");

// prepare ArrayList which will contain infos
ArrayList infoList = new ArrayList();

// obtain langauge!
Language lang = new Language("en");

ManufacturerInfo info = new ManufacturerInfoImpl();
info.setLanguage(lang);
info.setInfo("This is an info");
infoList.add(info);
// same for other langauges
// ....
manufacturer.setManufacturerInfo(infoList);

// now try to write it
db.create(manufacturer);

// manufacturer is created but  infos aren't.

        My mapping file looks like this:

<mapping>

    <class name="LanguageImpl"
    identity="languageId" key-generator="UUID">
        <map-to table="language" xml="Language"/>
        <field name="languageId" type="string">
            <sql name="language_id" type="char"/>
            <bind-xml node="attribute"/>
        </field>
        <field name="code" type="string">
            <sql name="code" type="char"/>
            <bind-xml node="attribute"/>
        </field>
    </class>

    <class name="ManufacturerInfoImpl"
     identity="manufacturerInfoId" key-generator="CUUID">
        <map-to table="manufacturer_info" xml="ManufacturerInfo"/>
        <field name="manufacturerInfoId" type="string">
            <sql name="manufacturer_info_id" type="char"/>
            <bind-xml node="attribute"/>
        </field>
        <field name="manufacturer"
        type="net.zuckerfrei.jobst.data.ManufacturerImpl">
            <sql name="manufacturer_id"/>
            <xml name="manufacturer" node="element"/>
        </field>
        <field name="info" type="string">
            <sql name="info" type="char"/>
            <bind-xml node="element" name="Info"/>
        </field>
        <field name="language"
        type="net.zuckerfrei.jobst.data.LanguageImpl">
            <sql name="language_id"/>
            <bind-xml node="element"/>
        </field>
    </class>

    <class name="ManufacturerImpl"
    identity="manufacturerId" key-generator="UUID">
        <map-to table="manufacturer" xml="Manufacturer"/>
        <field name="manufacturerId" type="string">
            <sql name="manufacturer_id" type="char"/>
            <bind-xml node="attribute"/>
        </field>
        <field name="manufacturerName" type="string">
            <sql name="manufacturer_name" type="char"/>
            <bind-xml node="element" name="ManufacturerName"/>
        </field>
        <field name="manufacturerInfo"
         type="ManufacturerInfoImpl"
         required="true" collection="arraylist">
            <sql many-key="manufacturer_id"/>
            <bind-xml name="ManufacturerInfo" node="element"/>
        </field>
    </class>

</mapping>

        (The sample code shown here is a part of a larger mapping
        file, and java code above is also truncated; irrelevant parts
        are omitted).

        What am I doing wrong here? Is it even possible to persist
        newly created object with its complete hierarchy?

        Thanks
-- 
Davor Cengija
[EMAIL PROTECTED]

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

Reply via email to