Re: JPA identity : primary-key unicity violated


stephane
 

Thanks Andy.
You're right about reserving a value generator. It can safely be done in the same connection than the Insert.

    1. I'm simply pointing the db lock remain until the transaction ends. Then a concurrent transaction reserving another sequence value is blocked by this db lock.
    2. As you also know db locking has database related side effect. Some database implement row lock as page lock. While page can contain several record (depending of the length of the record), locking a record locks several rows.

If my memory is still good, db2 do this and have by default pages of 4K. MySQL have a real row lock (others I don't know)... Considering the small size of our sequence table the chance to face this situation is high.

eg. in my app, I have 22 sequences for a total of 194 characters (the entire table is stored in one single page)

--
Stephane

Join main@datanucleus.groups.io to automatically receive all group messages.