I attached a failing unit test showing my intentions.
I think it is related to the embedded resource Spring.Data.Common.dbproviders.xml:
<constructor-arg name="errorCodeExceptionExpression" value="Number.ToString()"/>
"Number" isn't a property of System.Data.SQLite.SQLiteException. The correct property might be "ErrorCode" of the Enum-Type "SQLiteErrorCode".
I tried the following things without success:
- I added a custom dbProviders.xml "the crude way" (as described here http://www.springframework.net/doc-latest/reference/html/dbprovider.html#dbprovider-dbprovider)
but since the SessionFactoryUtils' NewAdoExceptionTranslator(...) looks for the first matching DbProvider (GetDbProvider(..)) and the additionally added DbProvider is the last one in the providerNames (line 666, SessionFactoryUtils.cs), still the DbProvider with a ErrorCodeExceptionTranslator using the wrong errorCodeExceptionExpression will be returned.
Also the "errorCodeExceptionExpression" is only available as a constructor argument, not as a property, so property overwriting of errorCodeExceptionExpression via Spring.Objects.Factory.Config.PropertyOverrideConfigurer is not possible either.
- I then declared the Spring.Data.Support.ErrorCodeExceptionTranslator explicitly using the a DbProvider (with "ErrorCode" instead of "Number" as the errorCodeExceptionExpression) and inject it into the LocalSessionFactoryObject instance so the localSessionFactoryObject doesn't have to call SessionFactoryUtils.NewAdoExceptionTranslator(sessionFactory) which would return a new AdoExceptionTranslatort the wrong DbProvider instance.
Still the exception won't be translated properly.
I was able to reduce the necessary steps and debug the attached unittest. It seems that the SQLiteErrorCode-Enumeration's ToString representation (e.g. "Busy") is used instead of the integer value casted to string (e.g. "5").
A suitable errorCodeExceptionExpression could be "((int)ErrorCode).ToString()" but this isn't parseable by spring.
Maybe the ExtractErrorCode(...) of the ErrorCodeExceptionTranslator has to handle it differently (line 167, LocalSessionFactoryObject.cs) and has to use the string represnetation of the enums integer value instead of the string representation of the Enumeration.
Maybe there is already a built in solution I haven't found?