> an pluggable exception factory (in open-jpa) might make this approach > a little easier
To a certain extent, such a beast already exists -- see DBDictionary.newStoreException(). We have special handling for HSQLDB and JDataStore to add information about referential integrity constraint types if the exception created is a ReferentialIntegrityException; similar logic could be added for other databases. The logic in DBDictionary.newStoreException() only knows that SQL code 23000 means "referential integrity constraint of some sort". -Patrick -- Patrick Linskey BEA Systems, Inc. _______________________________________________________________________ Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it. > -----Original Message----- > From: robert burrell donkin [mailto:[EMAIL PROTECTED] > Sent: Wednesday, April 04, 2007 9:57 AM > To: open-jpa-dev@incubator.apache.org > Subject: Re: why not an EntityExistsException was thrown? > > On 4/4/07, Craig L Russell <[EMAIL PROTECTED]> wrote: > > If you look at the exception that is thrown from the > database, it's a > > pretty general exception. > > > > "The statement was aborted because it would have caused a duplicate > > key value in a unique or primary key constraint or unique index > > identified by 'SQL070403054930170' defined on 'BSC'." > > > > This might have been caused by a unique constraint, which would not > > be properly reported as EntityExistsException. > > > > Sadly, there is no standard SQL exception that specifically > tells the > > provider (OpenJPA) that there was a primary key constraint > violation. > > And you might also note that every database has its own way > to report > > exceptions like this. > > > > What the EntityExistsException does is to report that there is > > already an entity with the same primary key in the persistence > > context. It doesn't report that there was a problem writing the > > entity to the database. > > <snip> > > > If you're keen on "fixing" this situation, I'd encourage you to > > volunteer to look at the databases and how they report unique and > > primary key constraint violations and see if it's possible to parse > > the sql code and report string to positively identify a primary key > > constraint violation. > > an pluggable exception factory (in open-jpa) might make this approach > a little easier > > - robert > Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.