I don’ t know how to insert a row in the child table that has an attribute that references to the column ID (primary key of the father Table)in the same transaction because i dont know the father primary key if i don’t commit the transaction.
Is there a way to solve this problem?
3
Answers
You already answered your question: you don’t have enough data before transaction’s commit. Maybe try something like nested transactions? Note that not every database supports this feature.
Mysql has LAST_INSERT_ID() function.
When you have executed your statement, call getGeneratedKeys() to fetch the generated keys: