I have a 2 table named A and B which are one to many relationship. I can not successfully add the data to table A and B at the same time. The problem is how can i make the foreign key in table B same with the primary key in table A. It only work when i explicitly assign the foreign key to it but how do i know the primary key at this stage because the "a" object have not added to the database. How to solve it?

a.setBs(b);
session.save(a);