A deadlock is often caused by ordering problems
Transaction1 lock A
Transaction2 lock B
Deadlock! Transaction1 holds A but wants B and
Transaction2 holds B but wants A.
1) Rearrange the access so that A is always before B
or B is always before A
2) The latest versions of JBoss will rollback transaction2
which introduced the deadlock and retry it.
3) Use read only access so that locks are maintained
for very long if that fits your locking requirement
4) Use optimistic locking and code for rollbacks.