Hi,
 
We are in a desperate situation and if there is no solution to this , it could have serious implications on the project which we are working on now :-(( . so if anyone knows anyway to solve this please tell... the lazy loading method suggested by Margaret Martin did not work.
 
 
We have a Doctor class whch is having N-1 relation with a Department class. In our test code when multiple threads tried to load and update different Doctor objects simultaneously, all but one are getting LockNotGranted(persis t.deadlock) exceptions.  The objects are loaded in Shared mode and cache-type is set to unlimited. Going through the castor code our finding is that:
 
Suppose there are two Doctors Doc1 & Doc2 both belonging to the same Department Dept1.
 
When a transaction T1 loads Doc1, Doc2 is also loaded because of its relation with the same Department and thus the T1 gets a read lock on Doc2 also.
 
When another concurrent Transaction T2 loads Doc2, Doc1 is also loaded because of its relation with the same Department and thus the T2 gets a read lock on Doc1 also.
 
When T1 requests for a write lock (upgrade using db.lock()) on Doc1, the request cannot be satisfied immediately as T2 is having read lock on Doc1
 
When T2 requests for a write lock (upgrade using db.lock()) on Doc2, the request is not satisfied as T1 is having read lock on Doc2, and here a dead lock is detected (in detectDeadLock() method of ObjectLock.java)
 
 
 
MAPPING.XML
 
<mapping>
 
 
 
  <!--  Mapping for Department-->
 <class name="Department" identity="id" key-generator="MAX" access="shared" >
 
 <cache-type type="unlimited" />
 <description>User</description>
  <map-to table="Department" />
 
  <field name="id" type ="long">
   <sql name="pk_department_id" type="bigint"/>
  </field>
  <field name="deptName" type="string">
   <sql name="deptName" type="varchar" dirty="check"/>
  </field>
 
  <field name="doctors" type="Doctor" required="false" collection="arraylist">
   <sql many-key="dept_id"/>
  </field>
 </class>
 

  <!--  Mapping for Doctor-->
 <class name="Doctor" identity="id" key-generator="MAX" access="shared" >
 
 <cache-type type="unlimited" />
 <description>Doctor</description>
  <map-to table="doctor" />
 
  <field name="id" type ="long">
   <sql name="pk_doctor_id" type="bigint"/>
  </field>
  <field name="userName" type="string">
   <sql name="UserName" type="varchar"  dirty="check"/>
  </field>
  
  <field name="dept" type="Department">
   <sql name="dept_id" />
  </field>
 </class>
  </mapping>
 
We are in urgent requirement of a solution and the we are not in a position to set cache-type to none due to performance issues.
 
Arun Sudhakaran,
Softex Computer Consultants.
E-Mail : [EMAIL PROTECTED]

Reply via email to