Hi,
I have a method in which I first persist an entity to a table (enclosed in a transaction and using transaction.commit). Then I issue a statement to retrieve all the entities in the table and use that entry to add another entity to a different table.
Code:
method()
{
(using transaction)
{
save to table1 using tx.commit(); //step 1
}
(using transaction)
{
retrieve above entry from database(); //step 2
save another entity to table2 with a relation to the entity in table1 using tx.commit(); //step 3
}
}
The issue that I am facing is that in step 3, it is saying that it cannot find the item created in step1. This happens intermittently. To investigate this I setup a sql trace. When the method works correctly, the insert query from step 1 is issued first followed by the retrieve query from step2. But when the method fails, the corresponding trace shows that the query from step 2 is being issued first followed by the insert query from step 1.
The nHibernate documentation states that if a commit is done in a transaction, the query is sent immediately to the database. If that is the case, why are the sql statements being issued in that order?
Thanks,
Sandeep