Affects: 5.3.x

In general, it's possible to cancel a database query happening in thread A from another thread B. For example, with Hibernate this is done via the method Session.cancelQuery(). Doing this is perfectly normal.

When a query is canceled, some kind of "query canceled" exception gets thrown in thread A.

However, Spring does not have a generic DAO exception subtype for "query canceled" exceptions.

So this is a feature request for Spring to define a generic subtype for "query canceled" exceptions. For example it could be named something like this:

public class QueryCanceledException extends NonTransientDataAccessException

Note, Hibernate does not currently define a corresponding ORM-layer exception, but I've filed feature request for that. Other ORM layers may already define such exceptions, I don't know. If they don't, they should :)

Regardless, Spring should define a QueryCanceledException because this is a real and legitimate error category.

More importantly, application code needs to be able to distinguish a QueryCanceledException, which is an expected non-error outcome, from other exceptions that represent real errors.

Comment From: snicoll

@archiecobbs thanks for the suggestion. Let's see if the Hibernate issue pans out and we can reconsider here if they provide support.

Comment From: jhoeller

JDBC itself does not indicate a query cancellation either, it's just MySQL having a specific SQLException subclass for it. Without clear indications at the resource level there - neither in JDBC nor in Hibernate -, I'm not sure we can do this any time soon.

Comment From: snicoll

The issue hasn't moved for a year so I suggest we close this. We can reopen if it turns out some external changes make it more likely to be actionable.