We are experiencing a deadlock occasionally during a merge on an entity.
The entity - Application - has a OneToMany relationship with EduWish using CascadeType.ALL and CascadeType.DELETE_ORPHAN.
The EduWish below has three OneToOne relationships to EduWishInst.
Please see the entities in the code at the end of this message.
We are basically in a JPA setting but use CascadeType.DELETE_ORPHAN to make sure garbage data is not left in the database.
Calling jpaTemplate.merge(application) with an application that has some of its EduWish deleted can cause (moderate load suspected) a deadlock on the EduWishInst table:
The deadlock is on:
delete from EduWishInst where id=:v0 from both sessions participating in the deadlock.
Code:
Deadlock graph:
---------Blocker(s)-------- ---------Waiter(s)---------
Resource Name process session holds waits process session holds waits
TM-00016380-00000000 80 12 SX SSX 84 926 SX SSX
TM-00016380-00000000 84 926 SX SSX 80 12 SX SSX
It seems each session tries to get a table lock while already holding a row lock.
Any idea why this is happening? We suspect that the DELETE_ORPHAN may be the culprit.
The environment is:
Weblogic 9.2
Oracle 11g
JPA
Hibernate 3.2.6.ga
Hibernate-entitymanager 3.3.2.GA
Spring 2.5.6
Code:
@Entity
public class Application {
...
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
@Fetch(value = FetchMode.SUBSELECT)
@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List<EduWish> educationWishes;
...
}
@Entity
public class EduWish {
...
@OneToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
private EduWishInst alfaInstitution;
@OneToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
private EduWishInst bravoInstitution;
@OneToOne(cascade = {CascadeType.ALL},fetch = FetchType.EAGER)
private EduWishInst charlieInstitution;
...
}
@Entity
public class EduWishInst {
...
}