Incorrect exception translation when using Oracle

Description

When a not-null constraint is broken, Oracle will throw the following exception:
java.sql.SQLException: ORA-01407: cannot update ("STARS_SECURITY"."PRIVILEGE"."NAME") to NULL
with SQLState=72000 and vendorCode = 1407

This reaches SQLStateConversionDelegate, where it wrongly interpreted as a MySQL specific exception; this is the exact code that does the interpretation:

// MySQL Query execution was interrupted
if ( "70100".equals( sqlState ) ||
// Oracle user requested cancel of current operation
"72000".equals( sqlState ) ) {
throw new QueryTimeoutException( message, sqlException, sql );
}

which leads to it being translated to a QueryTimeoutException.

The SQLStateConversionDelegate should could first look at the vendor code to be able to then interpret the SQLState correctly, based on that vendor.

This is also consistent with the Oracle documentation where 72000 is a "SQL execute phase errors":
http://docs.oracle.com/cd/E15817_01/appdev.111/b31228/appd.htm

Environment

Ubuntu Linux 12.04 32 bit, Oracle Database 11g Release 11.2.0.2.0

Activity

Show:
Arnaud Brunet
February 19, 2013, 11:26 PM

In the case of ORA-01013, the error is really a TimeoutException.
You can see the correspondence between the code and the error SQLState Oracle in oracle/jdbc/driver/errorMap.xml in ojdb6.jar.

Here an extract for sqlState = 72 000 :

As you can see SQLState 72000 usually corresponds to a generic SQLException.

Lukasz Antoniak
March 30, 2013, 5:43 PM

You can easily workaround this issue by extending Oracle dialect and overriding Dialect#buildSQLExceptionConversionDelegate() method. Review linked pull request for details.

Brett Meyer
April 11, 2013, 8:38 PM

Thanks to for the pull request.

Fixed

Assignee

Lukasz Antoniak

Reporter

Eugen Paraschiv

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure