This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi everyone , i have a problem persisting to the database using jpa . I am getting this exception 11:32:09,508 ERROR [JDBCExceptionReporter] ORA-02049: timeout: transacci¾n distribuida esperando bloqueo
I have two entities with the following code:
The other entity is
This is where i persist
What i basically do here is :
1. populate and persist a Reintegro type object , so as to get a sequence number (idReintegro) from a sequence generator
2. find and persist other entities (No problem here)
3. Take the sequence obtained in step 1 (idReintegro) , assign it to aportePortafolioDos object (foreign key value)
4. Persist the aportePortafolioDos object
The thing is that once the persistence context is synchronized with the Oracle 11g database , it hangs for a few minutes and then throws the exception ORA-02049: , which indicates there is a lock . The lock occurs while trying to persist aportePortafolioDos on an insert statement.
If I disable the foreign key on the table mapped by AportePortafolioDos , everything works as expected . but if the foreign key is active then i get the deadlock.
I have been trying to find a solution for days , to no avail. Is there anything to do at all ? Please help!!!
I'm no expert on ORM, so I'm just guessing based on what you wrote: did you index the foreign key? If you're deleting from a parent table (which I assume is happening when you persist), Oracle needs to lock entire child table if there is not an index on its foreign key.
Generally, foreign keys should always be indexed in Oracle. Only when you never delete from the parent table, you don't need the index on foreign key. And by "you delete from a table", I actually mean "your persistence framework deletes from a table".