Java Reference
In-Depth Information
By default, Spring will look up an exception from the sql-error-codes.xml file located in the package. However, you can override some of the mappings by
providing a file with the same name in the root of the classpath. If Spring can find your custom file, it
will look up an exception from your mapping first. However, if it does not find a suitable exception there,
Spring will look up the default mapping.
For example, suppose that you want to map your custom DuplicateKeyException type to error code
23505 . You have to add the binding via a CustomSQLErrorCodesTranslation bean, and then add this bean
to the customTranslations category.
<?xml version="1.0" encoding="UTF-8"?>
" ">
<bean id="Derby"
<property name="databaseProductName">
<value>Apache Derby</value>
<property name="useSqlStateForTranslation">
<property name="customTranslations">
<ref local="myDuplicateKeyTranslation" />
<bean id=" myDuplicateKeyTranslation"
<property name="errorCodes">
<value> 23505</value>
<property name="exceptionClass">
Now if you remove the try/catch block surrounding the vehicle insert operation and insert a
duplicate vehicle, the Spring JDBC framework will throw a My DuplicateKeyException instead.
However, if you are not satisfied with the basic code-to-exception mapping strategy used by the
SQLErrorCodes class, you may further implement the SQLExceptionTranslator interface and inject its
instance into a JDBC template via the setExceptionTranslator() method.
3-7. Problems with Using ORM Frameworks Directly
Suppose you are developing a course management system for a training center. The first class you create
for this system is Course . This class is called an entity class or a persistent class because it represents a
Search WWH ::

Custom Search