catchAndRethrow
Talks about:
<a class="post-tag post-tag-frontmatter" href="/tags/frontmatter">frontmatter</a>, and <a class="post-tag post-tag-sql" href="/tags/sql">sql</a>
Catch exceptions during SQL execution and re-throw them as RuntimeExceptions
Configuration Options
Option: ’true'
The default value for catchAndRethrow
is true
. This will catch any SQLException
that happen during SQL execution and re-throw them as RuntimeExceptions
.
package com.example.persistence;
public class SomeRepository {
public void writeSome() {
// ... some code
}
// ... rest of generated code
}
Option: ‘false’
In case you want to handle SQLException
s yourself, set catchAndRethrow
to false
.
package com.example.persistence;
import java.sql.SQLException;
public class SomeRepository {
public void writeSome() throws SQLException {
// ... some code
}
// ... rest of generated code
}
Related Options
- annotations: The additional annotations to be placed on generated methods.
- createConnection: Controls whether the generated code should create/open connection itself or use a given connection.
- description: The description for the SQL statement
- executeBatch: Generate methods that are executed as batch
- executeBatchPrefix: The method prefix to use for generated methods that execute in a batch.
- executeBatchSuffix: The method suffix to use for generated methods that execute in a batch.
- executeOnce: Generate methods that are executed once with the given parameters
- executeOncePrefix: The method prefix to use for generated methods that execute once.
- executeOnceSuffix: The method suffix to use for generated methods that execute once.
- name: The name of the SQL statement
- parameters: The parameters of the SQL statement.
- repository: The fully qualified name of the target repository class.
- resultRowConverter: The alias or fully-qualified name of the converter to use
- returningMode: The returning mode of the SQL statement.
- throwOnMultipleResults: Throw an exception in case a statement using
ReturningMode.SINGLE
produces more than 1 result. - type: The type of the SQL statement.
- vendor: The vendor name of the database the SQL statement is intended for
- writesReturnUpdateCount: Writing method which are using
ReturningMode.NONE
return the number of affected rows instead.
Front Matter
In order to configure this option, place the following code in the front matter of your SQL statement:
-- catchAndRethrow: configValue
SELECT something
FROM your_database_schema
WHERE some_column = :some_value