We've having a problem doing an insert into two tables in a single transaction in our H2 database using EclipseLink JPA.
The database schema looks something like ... Table A {..., IP_ADDRESS Varchar2( 15 ) not null }
Table B {...,
IP_ADDRESS Varchar2( 15 ) not null,
constraint MY_FK foreign key (IP_ADDRESS) references A
}
The problem we are having is that the foreign key constraint on B is making the transaction fail.
We're doing this:
entityManager.getTransaction().begin();
entityManager.merge ( Save to A transaction ); entityManager.merge ( Save to B transaction );
entityManager.getTransaction().commit();
It looks like JPA is trying to do the save to B first and failing. Or perhaps it is checking the constraint on B first?
At any rate, what we'd like to do ideally is something like what I recall from many years ago, using PL/SQL on oracle:
BEGIN
Do the insert on A;
Do the insert on B;
commit;
End;
I don't think Oracle looked at the constraint until the transaction was complete. Or allowed it complete because the uncommitted version of the transaction did not violate the constraint.
Any thoughts? I looked at the documentation and have not found anything helpful yet.
Thanks