Usually, when you use mysql, you have an auto incremented primary column in your tables. So MySQL handle itself the generation of the id for each entry and you should not set it yourself. That's what we do with HikaShop's tables. All the tables have a primary key which is auto increment, and it's mysql which attributes the id so there is no need for transactions. Then, once you did your insert, you can run another query to get the id generated if you need it. There is a function for that in Joomla:
$id = $database->insertid()
There is of course a small probability that an insert has been done between your insert and that function call, in which case you wouldn't get the correct id. That's however how Joomla handles the inserts and I've never seen a problem with that. Of course, you can always add your lock table yourself in your code to reduce that probability to 0.