In my application, I have entities for Registration, Bill and BillLineItems. Registration has OneToOne relationship with Bill, and Bill has OneToMany with BillLineItems. There is a mapping table between Bill and BillLineItems as per the default hibernate strategy.
When the user creates line items to be added to a bill and submits, I do the following (code is long, so I am summarising): -Start a new transaction -find() the appropriate registration object -Validate each line item and put it into a temporary list -If any item shows an error, rollback the transaction and return to the screen; if not, put item into a list -Add the list into the bill object of registration -Do merge() on registration -Commit the transaction
FlushMode is AUTO.
This works fine 99.9% of the time. But once in a while (about one transaction per day), there are line items in the BillLineItems table for which there are no mapping entries in the mapping table. These items are just hanging and are not part of any bill. Users did not report any exception, nor is there any exception in the logs (debug is enabled). CAn anyone tell me what's happening? My only guess is that some items got flushed before a validation error was reached. But this is a common scenario and I cannot understand why it should occur so rarely. At every validation error I do a rollback anyway. I changed to Flushmode COMMIT and have not encountered any hanging row for the last two days. Don't know if it has fixed the problem.
But I really need to know if tehre is something wrong I am doing or expecting hibernate to do. Please help.
|