File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes java.sql.BatchUpdateException: ORA-02049 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "java.sql.BatchUpdateException: ORA-02049" Watch "java.sql.BatchUpdateException: ORA-02049" New topic

java.sql.BatchUpdateException: ORA-02049

Marcel Jacome

Joined: Feb 06, 2009
Posts: 26
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!!!
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

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".
I agree. Here's the link:
subject: java.sql.BatchUpdateException: ORA-02049
It's not a secret anymore!