I assume that you are using one of the MVCC-based DBMSs .
If the transaction isolation level does not exceed READ COMMITTED, you can reduce the likelihood of conflict by issuing a request to check for the existence of cities with the same name
before inserting a new one.
Please note that saveOrUpdate()
will not help here, since name
not a primary key. Also note that you cannot prevent a conflict at all (at least not using some DBMS-specific functions), since this is basically an example of writing an anomaly of skew that cannot be prevented in an MVCC-based DBMS.
In addition, if the atomicity of importing an XML file is not critical, you can split the long transaction into several shorter ones and simply repeat them if the restrictions are violated.
axtavt
source share