Hi Andreas,

changing the workhours in a short transaction should work with following
 code. Take care to load and change objects in the same transaction (
not commit after load).

       db_ktrans.begin();
       OQLQuery query = db_ktrans.getOQLQuery(
           "SELECT a FROM worktime_monthly a WHERE id=$1");
       query.bind(id);
       QueryResults results = query.execute();
       worktime_monthly wtm = (worktime_monthly) results.next();
       ArrayList wtm_ah = wtm.getDaily_hours();
       for (Iterator itr = wtm_ah.iterator(); itr.hasNext();)
       {
           worktime_daily wd = (worktime_daily) itr.next();
           wd.setWorkhours(Integer.valueOf(0));
       }
       db_ktrans.commit();
       db_ktrans.close();

What I am wondering about is that you map workhours as String but call
its setter with Integer. Do you have to different setters ?

Which release of castor are you using ?

Having said that we are working on the issue that throws an exception if
the updated object references another object.

Ralf


Andreas Vombach schrieb:
> With a 1:m castor mapping like
> 
> <class name="worktime_monthly" identity="id"
>   key-generator="MAX">
>   <map-to table="worktime_monthly"/>
>     <field name="id" type="integer">
>       <sql name="ID" type="integer" />
>     </field>
>     <field name="totalhours" type="java.lang.String">
>       <sql name="TOTALHOURS" type="char" />
>     </field>
>     <field name="daily_hours" type="worktime_daily" collection="arraylist">
>       <sql many-key="PARENT_worktime_monthly"/>
>     </field>
>   </class>
> 
> <class name="worktime_daily" identity="id"
>   key-generator="MAX"
>   depends="worktime_monthly">
>   <map-to table="worktime_daily"/>
>     <field name="id" type="integer">
>       <sql name="ID" type="integer" />
>     </field>
>     <field name="workday" type="integer">
>       <sql name="WORKDAY" type="integer" />
>     </field>
>     <field name="workhours" type="java.lang.String">
>       <sql name="WORKHOURS" type="char" />
>     </field>
>     <field name="parent_worktime_monthly" type="worktime_monthly">
>       <sql name="PARENT_worktime_monthly" />
>     </field>
>   </class>
> 
> 
> I can change values of worktime_daily fields with a LONG transaction
> using the jdo.update method e.g.
> 
>        db_ktrans.begin();
>        OQLQuery query = db_ktrans.getOQLQuery("SELECT a FROM
> worktime_monthly a WHERE id=$1");
>        query.bind(id);
>        QueryResults results = query.execute();
>        worktime_monthly wtm = (worktime_monthly) results.next();
>        db_ktrans.commit();
>        ArrayList wtm_ah = wtm.getDaily_hours();
>        for (Iterator itr = wtm_ah.iterator(); itr.hasNext();)
>        {
>            worktime_daily wd = (worktime_daily) itr.next();
>            wd.setWorkhours(Integer.valueOf(0));
>        }
>        db_ktrans.begin();
>        db_ktrans.update(wtm);
>        db_ktrans.commit();
>        db_ktrans.close();
> 
> This long transaction works fine as long the worktime_monthly structure
> does not hold a relationship to another object.
> If so it will throw an exception that it "links to another object which
> is not loaded/updated/created in this transaction".
> To prevent this my thought is to omit the lines "db_ktrans.begin();" and
> "db_ktrans.update(wtm);" at the end to convert it to a short transaction.
> Doing this does not seem to change the dependent values worktime_daily,
> so I wonder is a long transaction needed?
> I hope I was clear enough, please ask if this example is not
> understandable - I searched in the test suite of the castor source for a
> similar example but did not really understand how updates of dependent
> objects are handeled - at least not with a long transaction ...
> 
> Thanks in advance for your help!
> 
> -------------------------------------------------
> If you wish to unsubscribe from this list, please send an empty message
> to the following address:
> 
> [EMAIL PROTECTED]
> -------------------------------------------------

-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to