-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Labels
bugSomething isn't workingSomething isn't workingquestionFurther information is requestedFurther information is requested
Description
Describe the bug
In spring boot 3.4.x java.sql.Array#getResultSet
causes a "underlying connection has changed" exception when the surrounding transaction/connection is read only.
Expected Behavior
no exception thrown
What plugins are used? What other connection properties were set?
?wrapperDialect=aurora-pg&wrapperProfileName=F0
with postgres 17.4 aurora cluster of 1rw, 1ro node
Current Behavior
Reading a jdbc array via its java.sql.ResultSet
throws exception about the read only connection changing.
Reproduction Steps
@Component
@AllArgsConstructor
public FancyDao {
private final NamedParameterJdbcTemplate jdbc;
@Transactional(readOnly = true)
public List<String> getStuffs() {
var sql = """
with stuff(text_col) as (
values ('a'),('b'),('c'),('d'),('a')
)
select array(select distinct text_col from stuff) as text_values""";
var result = new ArrayList<String>();
jdbc.query(sql, rs -> {
result.addAll(collect(rs.getArray("text_values"), ResultSet::getString, Collectors.toList()));
});
return result;
}
static <T, A, R> R collect(Array array, RowMapper<T> mapper, Collector<T, A, R> collector) throws SQLException {
var accumulator = collector.accumulator();
var container = collector.supplier().get();
if (array != null) {
try (var rs = array.getResultSet()) {
while (rs.next()) {
accumulator.accept(container, mapper.mapRow(rs, 2));
}
}
}
return collector.finisher().apply(container);
}
}
Possible Solution
Not familiar with the JDBC spec, but the Array data should already be client side at this point, making checking the underlying connection a false positive.
Can also use java.sql.Array#getArray
to go around the issue, but it's a bit of a trap.
Additional Information/Context
No response
The AWS Advanced JDBC Driver version used
2.5.6
JDK version used
temurin 21
Operating System and version
fedora 42
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingquestionFurther information is requestedFurther information is requested