You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DataSourceUtils.prepareConnectionForTransaction can throw SQLException when calls con.setTransactionIsolation(definition.getIsolationLevel()) [SPR-7184]
#11843
The call to the method can throw an SQLException if the JDBC driver doesn't support the change of transaction isolation after the connection is in use. This is the case with Postgresql. The problem is that the method is called even if the transaction isolation of the connection is the same of the configured transaction isolation (in the transaction definition). In this case, the JDBC driver (Postgresql) bombs. I suggest to call the setter only when the configured transaction isolation is different than the connection one. Example:
...
// Apply specific isolation level, if any.
Integer previousIsolationLevel = null;
if (definition != null && definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
if (logger.isDebugEnabled()) {
logger.debug("Changing isolation level of JDBC Connection [" + con + "] to " +
definition.getIsolationLevel());
}
previousIsolationLevel = new Integer(con.getTransactionIsolation());
con.setTransactionIsolation(definition.getIsolationLevel());
}
...
// Apply specific isolation level, if any.
Integer previousIsolationLevel = null;
if (definition != null && definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
if (logger.isDebugEnabled()) {
logger.debug("Changing isolation level of JDBC Connection [" + con + "] to " +
definition.getIsolationLevel());
}
previousIsolationLevel = new Integer(con.getTransactionIsolation());
// Just a little check to avoid throwing an unnecessary SQLException
if (con.getTransactionIsolation() != definition.getIsolationLevel() {
con.setTransactionIsolation(definition.getIsolationLevel());
}
}
Alberto Mozzone opened SPR-7184 and commented
The call to the method can throw an SQLException if the JDBC driver doesn't support the change of transaction isolation after the connection is in use. This is the case with Postgresql. The problem is that the method is called even if the transaction isolation of the connection is the same of the configured transaction isolation (in the transaction definition). In this case, the JDBC driver (Postgresql) bombs. I suggest to call the setter only when the configured transaction isolation is different than the connection one. Example:
Affects: 3.0.2
Referenced from: commits 853eab8
The text was updated successfully, but these errors were encountered: