Hi there,
I am facing deadlock issues when more than 1 thread is trying to do parent.addToChild(child) in a transaction. According to the stacktrace and sql that is shown on the console, i got a "net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection" when a parent.addToChild(child) method is called.
which is caused by
Caused by: COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/SUN] SQL0911N T
he current transaction has been rolled back because of a deadlock or timeout. R
eason code "2". SQLSTATE=40001
On a successful run of the transaction using only a single thread, i see that there is an sql that retrieves all the children whose parent_id=? which falls in line with the lazyInitializationException above cos it is unable to retrieve the children.
By the way, the parent-child relationship is bidirectional. and inverse="true" is set on the parent side of the r/s
I suspect that because there is more than 1 thread adding children to the same parent and have not commited yet and more than 1 thread is doing a select on retrieving all the children of the same parent, this causes dirty reads.
Is this really the cause of the deadlock? if so how do i set the isolation level of hibernate? Shouldnt this be transparent to us? i mean i am sure that there are applications out there that have threads that add children to the same parent rite? if so have they met with the same problem as me and how did they solve it?
i am using jboss and using hibernate as a mbean service, database is DB2.
Please anyone with any directions pls help!!!!
Best Regards
|