Margaret,

        thanks for your reply. However, there are some limitations in
        my design. Please read further.

On Fri, 8 Mar 2002, Martin, Margaret wrote:

> Davor,
> In your mapping, you'll need to set up Language with
> depends=ManufacturerInfo and ManufacturerInfo with depends=Manufacturer. You
> also need to make the relationships bidirectional - so within the set/add
> methods for the ManufacturerInfos within Manufacturer, be sure and also set
> the manufacturer into the ManufacturerInfo (ditto for the set/add Languages
> within ManufacturerInfo)...

        Language doesn't depend on ManufacturerInfo, it's only used in
        in ManufacturerInfo, as well as in ProductInfo, CustomerInfo
        and many other different objects. The SQL tables look like
        this:

something_info_id | something_id | language_id | something_info

        Additionally, languages are already in the database and it is
        unlikely that I'll need another language for each
        ManufacturerInfo :-). So, how can I set the Language mapping
        to depend on many different objects? Also, if I have depends
        attribute I cannot persist the object explicitly (via
        db.create()) which is not god (I might from time to time have
        a need to create another language).

        However, I've followed your advices and now I can actually
        create Manufacturer with ManufacturerInfo, but, strangelly
        enough, manufacturer_id from the table above remains empty
        (empty string, not null).

        I'm having real troubles with Castor. I'm not even sure it's
        suitable for my purposes.

        Thanks again,

        Davor




>
> Hope this helps...
>
> Margaret Martin
>
> -----Original Message-----
> From: Davor Cengija [mailto:[EMAIL PROTECTED]]
> Sent: Friday, March 08, 2002 1:46 PM
> To: [EMAIL PROTECTED]
> Subject: [castor-dev] Creating object hierarchy
>
>
>       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