Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ private MapSqlParameterSource bindParameters(RelationalParameterAccessor accesso
JdbcValue jdbcValue = JdbcValueBindUtil.getBindValue(converter, value, parameter);
SQLType jdbcType = jdbcValue.getJdbcType();

if (jdbcType == JDBCType.OTHER) {
parameters.addValue(parameterName, jdbcValue.getValue());
} else {
if (jdbcType != null) {
parameters.addValue(parameterName, jdbcValue.getValue(), jdbcType.getVendorTypeNumber());
} else {
parameters.addValue(parameterName, jdbcValue.getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ void spelCanBeUsedInsideQueries() {
assertThat(paramSource.getValue().getValue("__$synthetic$__2")).isEqualTo("test-value2");
}

@Test // GH-2188
void shouldPreserveJdbcTypeOtherFromJdbcValueInStringBasedQuery() {

SqlParameterSource parameterSource = forMethod("findByCustomValue", Direction.class)
.withCustomConverters(DirectionToOtherJdbcTypeConverter.INSTANCE)
.withArguments(Direction.LEFT)
.extractParameterSource();

assertThat(parameterSource.getSqlType("value"))
.isEqualTo(JDBCType.OTHER.getVendorTypeNumber());
}

QueryFixture forMethod(String name, Class... paramTypes) {
return new QueryFixture(createMethod(name, paramTypes));
}
Expand Down Expand Up @@ -562,6 +574,9 @@ interface MyRepository extends Repository<Object, Long> {
@Lock(value = LockMode.PESSIMISTIC_READ)
@Query("SELECT * FROM person WHERE id = :id")
DummyEntity unsupportedWithLock(Long id);

@Query(value = "some sql statement") // GH-2188
List<DummyEntity> findByCustomValue(@Param("value") Direction value);
}

private static class CustomRowMapper implements RowMapper<Object> {
Expand Down Expand Up @@ -655,6 +670,17 @@ public String convert(ListContainer source) {
}
}

@WritingConverter // GH-2188
enum DirectionToOtherJdbcTypeConverter implements Converter<Direction, JdbcValue> {

INSTANCE;

@Override
public JdbcValue convert(Direction source) {
return JdbcValue.of(source.name(), JDBCType.OTHER);
}
}

private static class DummyEntity {
private final Long id;

Expand Down