Hello!

just one more questions about long transactions. The scenario:

1) Two classes: User and Group. One user can be in zero to many groups.
2) Normal mapping (see below)

Now I want to change the group of a user using long transactions. I do the 
following steps:

a) get the user object using db.begin();db.load(); db.commit(), display it to 
the user
b) user can change the group
c) get the selected group in a own transaction using OQL (db.begin(); 
OQL-stugg; db.commit();)
d) Updateting the user object: db.begin(); user.addGroup(group); 
db.update(user); db.commit();

This does not work. It seems that the transaction in which I get the group 
(step c above) has to be the same transaction that updates the object (step d 
above).
Is this true? If I put step c and step d in the same transaction, it works. 
What can I do so that it will work the way described above?
E.g. when I want to delete every group of the user and I call 
user.clearGroup() which does a <arraylist>.clear(), this can be called 
outside the transaction of step d.


--- The mapping.xml ---
<mapping>
  <class name="User" identity="id" key-generator="MAX">
      <map-to table="users" />

      <field name="id" type="integer">
          <sql name="id" type="integer" />
      </field>
      <field name="login" type="string">
          <sql name="login" type="char" />
      </field>
      <field name="groups" type="Group" collection="arraylist">
          <sql many-table="usersgroups_asgn" many-key="userid" 
name="groupid"/>
      </field>

  </class>

  <class name="Group" identity="id">
      <map-to table="groups" />

      <field name="id" type="integer">
          <sql name="id" type="integer" />
      </field>
      <field name="name" type="string">
          <sql name="name" type="char" />
      </field>
</class>

</mapping>

-- 
Dipl. Inform. Boris Klug, control IT GmbH, Germany

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

Reply via email to