Table synchronization, hibernate random thoughts

Data synchronization scheme between two identical tables (A->B) --
1. Directly delete the data in table B, insert the entire data
2. Create a temporary table, record the operation of table A, use fields to indicate new, delete, modify, and then Query the temporary table, and send the responses of those related operations to Table B.
3. Use SQL to compare the differences between the data on both sides. If table A is newly added, such as select * from A where not exists (select 1 from B where A.pk=B.pk), add this data to table B. If you delete it, the two tables can be reversed. If modified, select A.* from A ,B where A.filed1 <>B.field1 and A.field2<>B.field2 ... and A.pk =B.pk to query the records modified by A, and then update to The


extension : hibernate persists the modification of the record. Generally, when the modification operation is performed, because some fields on the page have not been changed, there will be a Null value. At this time, it is usually queried from the database first, and then copyNotNull (source, target does not matter) , but for the sake of performance, the detected ones will be used as targets, and the reasons will be explained below), -- at this time, if hibernate can judge the null value of fields like ibatis, it would be nice, and there is no need to query and copy again. Persist again. If the persistent record is in the persistent state, hibernate will compare the cached and new ones, and only update the modified ones, not all fields (should be handled like this, compare the field values ​​one by one, not equal, Put it in the Map, when doing the update, then splicing the fields and values ​​in the Map)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326658659&siteId=291194637