Hi,
thanks for the answers. Seems like optimistic locking is ok for your situation, judging by how infrequent this happens. However, there may be a few limitations we should examine first.
1. Is it reasonable for the code that copies the data to have UPDATE privileges on the SOURCE database?
2. Is it reasonable to add columns to each table in the existing schema?
If the answer is YES for 1 and 2, my suggestion is to use optimistic locking techniques. Example: add 2 columns to each table:
1. a lock_version column, specified as the "version" column in hibernate, usually of numeric type e.g. long, and default value 0.
2. 'archived' boolean column, default value=false
Now, instead of simply selecting rows and persisting them into the new database, select a row, set its archive column to 'true' and merge it back to the SOURCE database in the same transaction that writes to the second database. Hibernate will automatically increment the lock_version column. This will effectively implement optimistic locking, causing all but one of the concurrent transactions to fail when trying to copy the same rows. It may be possible to implement optimistic locking without the 'archived' column - if you can get hibernate to "think" that your source rows have changed and that it needs to increment the version column.
good luck :-)
|