rzo1 opened a new pull request, #330: URL: https://github.com/apache/openjpa/pull/330
https://issues.apache.org/jira/browse/OPENJPA-2913 Calling `Generator.allocate(n)` on a table based generator (`TableJDBCSeq`) could make it hand out IDs that were already used. On a fresh EntityManagerFactory, `allocate()` followed by `next()` started at 1, whatever value the sequence table already held. With several factories sharing the table, a factory that called `allocate()` after some `next()` calls could also continue into values another factory had already taken. Cause: `allocate()` reserves a new range in the sequence table and raises the upper bound of the in-memory block, but did not move the next value (`stat.seq`); only `next()` did that (`updateStatSeq`). Fix: in `TableJDBCSeq.setSequence`, the next value also moves to the value read from the table when the new range does not directly follow the block already held (`stat.max < cur`). That covers a fresh factory and a range after another factory's reservation. When the range directly follows the current block, the held values are kept as before. The next value only ever moves forward. Simply passing `updateStatSeq=true` from `allocateInternal()` would not work: the loop there could then alternate forever. `NativeJDBCSeq` reads the current value on `allocate()` and does not have this problem; `ValueTableJDBCSeq` and `ClassTableJDBCSeq` only call `setSequence` from their command line tool, unchanged. Tests (Derby): new `TestTableGeneratorAllocate`: `allocate()` and `next()` on a fresh factory after entities were persisted, and two factories taking blocks with one calling `allocate()`; no ID may repeat. Both fail without the fix. The openjpa-kernel, openjpa-jdbc and the full openjpa-persistence-jdbc suites pass (`TableJDBCSeq` is the default sequence). TCK: https://github.com/apache/openjpa/actions/runs/46485239568, Databases: https://github.com/apache/openjpa/actions/runs/46485245749 (running) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
