<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=benrowlands" rel="nofollow">Ben Rowlands</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5126?redirect=false" rel="nofollow">SPR-5126</a></strong> and commented</p>
<p dir="auto">The Spring DAO exception hierarchy is not fine grained enough to isolate duplicate key errors. A duplicate key error is an example of where an application may catch the exception and invoke alternative logic instead of just letting it fall down the stack.</p>
<p dir="auto">For example, we read messages from a queue and insert the data into a database. We explicitly catch a duplicate key insert exception as this indicates we've processed the same message earlier. This is more efficient than a guarding the update with a check-then-act (which also introduces a race condition that may lead to dup-key exception anyway).</p>
<p dir="auto">Additionally, if we use single-phase commit for our JMS and DB transactions (commit DB first then JMS) a failure scenario is that the DB transaction commits but the JMS transaction rollsback. In this case the message is delivered again and we get a dup-key exception. We can then safely ignore such duplicate messages.</p>
<p dir="auto">A dup-key error is currently classified as a DataIntegrityViolationException along with other errors such as a data bounds error so we can't simply catch this exception type. We could work around this be checking the vendor error-code/state however this is not portable and cumbersome.</p>
<p dir="auto">Ideally an exception like:</p>
<p dir="auto">public class DuplicateKeyException extends DataIntegrityViolationException { }</p>
<p dir="auto">Spring already provides mappings from vendor specific codes so it would be very powerful if it could provide a fine grained exception to allow this common duplicate-key handling pattern to be detected just using exception type.</p>
<p dir="auto">We currently use the following SQLExceptions to detect a dup-key:</p>
<ul dir="auto">
<li>Sybase: error-state=23000</li>
<li>DB2: error-state=23505</li>
</ul>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398090697" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9798" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9798/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9798">#9798</a> Add DuplicateKeyException to DAO exception hierachy (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=skaffman" rel="nofollow">Kenny MacLeod</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-6750?redirect=false" rel="nofollow">SPR-6750</a></strong> and commented</p>
<p dir="auto">The mvc:annotation-driven schema permits the specification of messageConverters, which are passed on to the generated AnnotationMethodHandlerAdapter. I'd like to see the ability to specify the customArgumentResolvers also.</p>
<p dir="auto">I suppose there's a fine line between making mvc:annotation-driven minimalist and supporting common use cases only, and simply duplicating every property from AnnotationMethodHandlerAdapter and DefaultAnnotationHandlerMapping.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0 GA</p>