throwOnMultipleResults
Throw an exception in case a statement using ReturningMode.SINGLE produces more than 1 result.
What a returning
single statement does when the database
answers with more than one row. Off, the first row is returned and the rest are dropped;
on, it throws.
A statement declared single is a claim that at most one row can match. Where that claim
rests on a unique constraint the database enforces, the check is redundant and the
default is right. Where it rests on you being sure — a lookup by something that ought to
be unique but is not constrained to be — turning this on converts a silent wrong answer
into a loud one.
It costs nothing at run time beyond reading one more row.
Configuration Options
Option: ‘false’
The default. A second row is ignored:
public final class TenantRepository {
public Optional<Tenant> findTenantBySlug(final String slug) {
// ... reads every row, answers with the first
}
}
Option: ’true'
A second row is a defect, and says so:
public final class TenantRepository {
public Optional<Tenant> findTenantBySlug(final String slug) {
// ... throws when the statement answers with more than one row
}
}
Related Options
Also in this group: annotations , catchAndRethrow , createConnection , description , executeBatch , executeOnce , generateConnectionOverloads , generateResultRowType , injectConverter , name , parameters , repository , resultRowColumns , resultRowConverter , resultRowType , returningMode , type , validateSchema , vendor , writesReturnUpdateCount .
Front Matter
In order to configure this option, place the following code in the front matter of your SQL statement:
-- throwOnMultipleResults: true
SELECT something
FROM your_database_schema
WHERE some_column = :some_value