On MySQL, in insertIntoA
you should be able to do:
SELECT LAST_INSERT_ID()
...on the same connection you used for the insert, assuming it's an identity
column value you're looking for.
EDIT: If you're doing that and it's not working (per your comment), I'd look at the middle layers to see what's going on. MySQL is fine with it:
mysql> create table A (id int(11) not null auto_increment, descr varchar(64), primary key (id));
Query OK, 0 rows affected (0.13 sec)
mysql> create table B (fk int(11) not null, descr varchar(64));
Query OK, 0 rows affected (0.06 sec)
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into A (descr) values ('Testing 1 2 3');
Query OK, 1 row affected (0.00 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 1 |
+------------------+
1 row in set (0.03 sec)
mysql> insert into B (fk, descr) values (1, 'Test complete');
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.03 sec)
mysql> select * from A;
+----+---------------+
| id | descr |
+----+---------------+
| 1 | Testing 1 2 3 |
+----+---------------+
1 row in set (0.02 sec)
mysql> select * from B;
+----+---------------+
| fk | descr |
+----+---------------+
| 1 | Test complete |
+----+---------------+
1 row in set (0.00 sec)
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into A (descr) values ('Second test');
Query OK, 1 row affected (0.01 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)
mysql> insert into B (fk, descr) values (2, 'Second test complete');
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.08 sec)
mysql> select * from A;
+----+---------------+
| id | descr |
+----+---------------+
| 1 | Testing 1 2 3 |
| 2 | Second test |
+----+---------------+
2 rows in set (0.02 sec)
mysql> select * from B;
+----+----------------------+
| fk | descr |
+----+----------------------+
| 1 | Test complete |
| 2 | Second test complete |
+----+----------------------+
2 rows in set (0.00 sec)
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into A (descr) values ('We''ll roll this one back.');
Query OK, 1 row affected (0.00 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 3 |
+------------------+
1 row in set (0.00 sec)
mysql> insert into B (fk, descr) values (3, 'Won''t see this one.');
Query OK, 1 row affected (0.00 sec)
mysql> select * from B;
+----+----------------------+
| fk | descr |
+----+----------------------+
| 1 | Test complete |
| 2 | Second test complete |
| 3 | Won't see this one. |
+----+----------------------+
3 rows in set (0.00 sec)
mysql> rollback;
Query OK, 0 rows affected (0.03 sec)
mysql> select * from A;
+----+---------------+
| id | descr |
+----+---------------+
| 1 | Testing 1 2 3 |
| 2 | Second test |
+----+---------------+
2 rows in set (0.00 sec)
mysql> select * from B;
+----+----------------------+
| fk | descr |
+----+----------------------+
| 1 | Test complete |
| 2 | Second test complete |
+----+----------------------+
2 rows in set (0.00 sec)