Oracle SELECT FOR UPDATE behaviour. Attempting to lock the same row twice in the same transaction

163 Views Asked by At

I have a transaction, where I insert 2 types of child entities in the database. Here is the pseudo-code:

LOCK parent with id=xyz;
INSERT into child1(...) values(...);

LOCK parent with id=xyz;
INSERT into child2(...) values(...);

This rowlock is imposed mostly to make sure that the parent is not being removed when child entities are being inserted.

Is there any issue with the structure of the transaction? I am worried that the second SELECT FOR UPDATE is gonna time out as the row is already locked.

Or is my worry baseless?

The reason I am asking such a question because I am getting:

ORA-30006: resource busy; acquire with WAIT timeout expired or DTP service is unavailable 
1

There are 1 best solutions below

0
On

If you have a foreign key constraint defined, Oracle automatically locks the parent while you are inserting the child. You don't need to try to do that yourself.