In my application I have a component that receive objects from another components and insert them to MySQL DB. Currently I'm buffering the objects and once in a while (few seconds) the objects are inserted to the DB using a batch (using JDBC, not hibernate).
I would like to break this objects to 2 objects, then two buffers, and finally insert them to 2 different tables.
My first thought was to use MySQL auto generated ID to tie the two sub-objects together in the table (as foreign key).
My problem is - how will I know the auto-generated ID for the 'father' object when I insert the 'child' object?
My ideas are:
- Generate my own ID before splitting the object and send the ID to the DB myself, without using MySQL auto-generated ID.
- Use stored procedure that will insert the first object, use MySQL's
LAST_INSERT_ID();
What do you think?