#245 CMP Create performance and SQLExceptionProcessing Service

JBossCMP (36)

To address bug 723908, a new <entity-command> has been
added which does not perform a SELECT to detect
duplicate primary keys but instead examines any
SQLException thrown.

Prior to 3.2.1, CMP attempted to detect a DuplicateKey
condition by performing a SELECT for a row with the
supplied primary key and throwing DuplicateKeyException
if any row existed. This required an SQL operation,
impacting performance, and suffered from a potential
race condition as no lock was taken on the PK value.

In 3.2.1 a new entity-command has been added that does
not perform this check but instead examines any
SQLException thrown by the INSERT to determine if a
DuplicateKeyException should be thrown.

This eliminates the addition SQL operation, closes the
race window and guarantees that a DuplicateKeyException
will be thrown if a suitable database constraint is in
place. For most databases, this will result in
DuplicateKeyException if any unique constraint is
violated, even for secondary keys.

As different JDBC drivers may indicate constraint
violations in different ways, an SQLExceptionProcessor
service has been added that can be used to classify an
SQLException raised by the driver. The supplied
implementation uses the ANSI SQL99 standard SQLState
code of "23000" to detect constraint violations.

To avoid migration issues, the default configuration
has not been modified and exception-based detection
must specifically be activated. The
SQLExceptionProcessor service is deployed only in the
"all" configuration.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks