datanucleus / datanucleus-rdbms

DataNucleus support for persistence to RDBMS Datastores
30 stars 67 forks source link

Fix BUG: Duplicated ID happen on MS SQL Server If run multiple JVM instance. #469

Closed amanraj2520 closed 1 year ago

amanraj2520 commented 1 year ago

Copied from https://github.com/datanucleus/datanucleus-rdbms/pull/354

use with (updlock) to support MS SQL Server.

andyjefferson commented 1 year ago

Why is there supportedOptions.add(LOCK_WITH_SELECT_FOR_UPDATE); in SQLServerAdapter when that RDBMS doesn't support FOR UPDATE ? (and where is this LOCK_WITH_SELECT_FORUPDATE defined? ... the variable had ROW added some versions ago) What is generateLockWithSelectForUpdate(...) when it is seemingly not called? Why isn't there simply a method on DatastoreAdapter (SQLServerAdapter) that returns "(UPDLOCK)" if that is the WITH option needed somewhere? In SequenceTable why is all of this code finding wherePos, when you know wherePos from several lines before when it is added?

andyjefferson commented 1 year ago

No reply.

Define WHAT you are trying to achieve. SequenceTable (aka value-generator=increment) will currently create SQL like this

SELECT {myColumn} FROM {myTable} WITH (UPDLOCK,ROWLOCK) WHERE {col}=?";

for SQLServer. Define what is incorrect about that. It is consistent with what is generated for a normal SELECT statement for that datastore. i.e the SQL generated by SequenceTable should be the same as that generated by SelectStatement.

Otherwise I'll close this

amanraj2520 commented 1 year ago

@andyjefferson There was some emergency at my end, so I was out for a couple of weeks. I have raised a fresh PR - https://github.com/datanucleus/datanucleus-rdbms/pull/472. Sincere apologies for the delay. Made the relevant changes