You probably do not want to do that.
A huge transaction places a considerable burden on any database engine. Also, if you're worried about working with outdated references, any process that may invalidate a reference will have to wait for your transaction to complete. Also, if the transaction is running for more than a few minutes, you risk that it is aborted by factors outside your control, such as hardware faults, power outages, or the database admin shooting down your transaction because it's blocking another process. You don't want your work rolled back, you want the productive work committed and another run restarted that finishes the remaining records.
I tend to design the data model so that you can directly read off each record whether it needs to be processed or not. That way, I can do single-record transactions: get the record, do whatever the process needs to do with it, update the status, finish the transaction. Hibernate will support you there in that it will collect all updates and write them out in a single batch at the end of the transaction.
The status can be anything. You talked about creating dependent records, so work only on those master table records where the dependent records don't exist yet. In other situations, I had records that needed to be upgraded once per month, so the nightly batch run will touch only those records that have a "last processed month" field that's older than the current month. Filtering out the already-done records can be made efficient by having the proper index in place and using a WHERE condition that will filter them out (via NOT EXISTS if it's "needs dependent records added", or via "last_modified is too old" if it's "needs to be processed once per day").
|