Hi there,
I am running into an oracle deadlock problem in developing an application with Hibernate 3.0 and WSAD 5.0 (integrated Edition).
I have a class mapped to a table: A->a, and a's primary key is another table, let's say d, foreign key.
So A and D classes are defined as below:
Code:
class A
{
Long key; // map to primary key
// more attributes defined
Map ds; // holds class D instances
}
class D
{
String type; // not unique but unique in the rows having the same foreign keys
String att1;
String att2;
Long key; // foreign key from class A
}
Class A metadata file has the following mapping:
Code:
<class name="A"
table="a"
lazy="true">
<id name="key"
type="long"
column="key"
unsaved-value="null">
<generator class="assigned"/>
</id>
<property ...></property>
<map name="ds"
lazy="true"
table="d"
cascade="delete">
<key column="key" not-null="true" />
<index column="type" type="string"/>
<composite-element class="D">
<property name="att1" column="col1" type="string"/>
<property name="att2" column="col2" type="string"/>
</composite-element>
</map>
</class>
The following is pseudo code of a transaction:
Code:
public void process(Long key)
{
Session session = sessionFactory.openSession();
Transact tx = session.beginTransaction();
try
{
A aa = session.get(A.class, aKey);
if(aa != null)
{
// process business logic
session.delete(aa);
tx.commitTransaction();
}
}
catch(HibernateException he)
{
tx.rollbackTransaction();
// may be rethrow as my own exceptions
}
finally
{
session.close();
}
}
Then I ran 200 threads, each of them had a unique key (I guarrantee that) passed to the process method, but I got oracle deadlock problem. I use default settings of transaction isolation level for both hibernate and oracle. I just don't under stand why I got deadlock problem.
Anybody can help me with that problem?
Thanks a lot in advance,
Jane