| From | Sent On | Attachments |
|---|---|---|
| Deyan Tsvetanov | Jul 19, 2010 5:43 am | |
| Deyan Tsvetanov | Jul 19, 2010 6:10 am | |
| Adrian Crum | Jul 19, 2010 6:15 am | |
| Deyan Tsvetanov | Jul 19, 2010 6:18 am | |
| Deyan Tsvetanov | Jul 19, 2010 6:22 am | |
| Adrian Crum | Jul 19, 2010 6:45 am | |
| Deyan Tsvetanov | Jul 19, 2010 8:19 am | |
| Adrian Crum | Jul 19, 2010 8:26 am | |
| Deyan Tsvetanov | Jul 19, 2010 8:42 am | |
| Scott Gray | Jul 19, 2010 2:06 pm | |
| Deyan Tsvetanov | Jul 22, 2010 12:32 am |
| Subject: | Entity Engine: GenericDuplicateKeyException | |
|---|---|---|
| From: | Deyan Tsvetanov (deya...@flexbrix.com) | |
| Date: | Jul 19, 2010 5:43:36 am | |
| List: | org.apache.ofbiz.user | |
Hi guys,
there is a problem in entity engine which I would like to fix.
Reproduction:
I am trying to create a party with a duplicate partyId.
In general I thought I have to expect a GenericDuplicateKeyException.
However the exception that I get is a regular GenericEntityException with a nested GenericDateSourceException one with nested PSQLException inside. The exception message is: ERROR: duplicate key value violates unique constraint "pk_party"
I believe it should be expected that a GenericDuplicateKeyException will be thrown in case of a duplicate primary key.
The solution for that would be to handle not only SQLException in
org.ofbiz.entity.jdbc.SQLProcessor
but it's subclasses as well and throw the corresponding entity engine
exceptions.
So the code:
} catch (SQLException sqle) {
throw new GenericDataSourceException("SQL Exception while executing
the following:" + sql, sqle);
}
would be changed to :
} catch ( SQLIntegrityConstraintViolationException icvEx ) {
throw new GenericDuplicateKeyException( "Duplicate key exception while
executing the following: " + sql , icvEx );
} catch (SQLException sqle) {
throw new GenericDataSourceException("SQL Exception while executing
the following:" + sql, sqle);
}
on all occurances of catching a SQLException where insert or update is executed.
-- deyan





