"Therefore, a commit is mandatory after the first table insert."
What?!
This makes no sense to me. There is zero technical need to commit a parent insert before adding a child in the same session:
create table t1 (
x int primary key
);
create table t2 (
x int references t1 (x)
);
insert into t1 values (1);
insert into t2 values (1);
select * from t1;
X
1
select * from t2;
X
1
Get rid of the commit and let rollback do the work for you!