realskywalker wrote:
The reason that I have to commit the first transaction is that it does not seen to give the lastest sequence number (DB trigger generated) of Table1 unless it is commited. This sequence number is needed for the second transaction.
I think you should look for another way to autoincrement the value that now incremented by your trigger via sequence number. In your case the two operations should be inside one transaction and you don't need any nested one.
What value do you need to autoincrement? If it is some property of the first object (tk), try this, it should work:
Code:
// insert a new row in Table1
tk = something ....
session.save(tk);
session.flush();
session.refresh(tk); // re-reads tk with updated property
// Based on new information of tk, update Table2
// but if update failed, I want to roll back Table1 transaction.
tkper.setTKId(tk); // some property of tk was changed by trigger and then re-read via session.refresh()
session.update(tkper);
session.flush();
tx.commit();
session.close();