You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Olaf Meske <ol...@iqnex.com> on 2003/04/16 22:58:57 UTC

Update statement during a clean read access ?

Hi ,

I've got a strange behavior with the transaction locking.
In an PB like the one in the faq "I don't like OQL, can I use the 
PersistenceBroker Queries within ODMG?" , I select a some parent objects 
with a lists of child objects.
After getting the list of parent objects I try to set a Transaction.READ
lock on all objects.
Until here everything is fine, but when I commit the Transaction (tx) 
itself, every parent object is updated (no one of the childs or the 
depending child lists!)

<---------- piece of code start -------------- >

PersistenceBroker broker = ((HasBroker) tx).getBroker();

broker.beginTransaction();
// ask the broker to perfom the query.
result = (ManageableCollection) broker.getCollectionByQuery(query);
broker.commitTransaction();

// read-lock all resulting objects to the current transaction
Iterator iter = result.ojbIterator();
Object toBeLocked = null;
while (iter.hasNext()) {
   toBeLocked = iter.next();
   //we can only lock objects, not attributes
   if (broker.hasClassDescriptor(toBeLocked.getClass())) {
     tx.lock(toBeLocked, Transaction.READ);
   }
}

// *until here everything is fine*
// but after tx.commit() every single parent object is updated
// with an UPDATE statement. But notbody changed any value
// because everything I do is getting a read lock on this objects?
// Any ideas how to fix these behaviour with the update statements?
// I realy have problems with these updates.
// Any help will be welcome.
tx.commit();
<---------- piece of code end  -------------- >

Everything I checked:
OJB.properties: set LockAssociations=READ -> no effect
remove the child list from repository.xml -> works!
(but I need the list :-( )

<--- here the repository stuff start ----->

<class-descriptor
   class="com.example.Parent"
   table="Parent">
   <field-descriptor id="0"
     name="id"
     primarykey="true"
     autoincrement="true"
     column="Id"
     jdbc-type="INTEGER"
   />
   <field-descriptor id="1"
     name="name"
     column="Name"
     jdbc-type="VARCHAR"
   />

   <collection-descriptor
     name="allChilds"
     element-class-ref="com.example.Child"
     proxy="true"
     orderby="childId"
     sort="DESC"
   >
     <inverse-foreignkey field-ref="parentId"/>
   </collection-descriptor>

</class-descriptor>

<class-descriptor
   class="com.example.Child"
   table="Child">
   <field-descriptor id="0"
     name="id"
     primarykey="true"
     autoincrement="true"
     column="Id"
     jdbc-type="INTEGER"
   />
   <field-descriptor id="1"
     name="parentId"
     column="ParentId"
     jdbc-type="INTEGER"
   />
   <field-descriptor id="2"
     name="childId"
     column="ChildId"
     jdbc-type="INTEGER"
   />
</class-descriptor>

<--- here the repository stuff start ----->


Thanks
Olaf