Skip to content

Commit 965e440

Browse files
DATAJDBC-341 - fixed, added tests, some polish.
1 parent 2b3fc3a commit 965e440

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ private T populateProperties(T instance, @Nullable Object idValue) {
324324
try {
325325
if (resultSet.findColumn(property.getColumnName()) > 0) {
326326
propertyAccessor.setProperty(property, readOrLoadProperty(idValue, property));
327-
} else {
328-
System.out.println(String.format("Column %s not found in result set. Use standard values.", property.getColumnName()));
329327
}
330328
} catch (SQLException e) {
331329
e.printStackTrace();
@@ -381,15 +379,12 @@ private Object readFrom(RelationalPersistentProperty property) {
381379
}
382380
Object value = null;
383381
try {
384-
// check if property is in the result set
382+
// check if property is in the result set
385383
// if not - leave it out
386384
// DATAJDBC-341
387385
if (resultSet.findColumn(property.getColumnName()) > 0) {
388386
value = getObjectFromResultSet(path.extendBy(property).getColumnAlias());
389-
} else {
390-
System.out.println(String.format("Column %s not found in result set. Use standard values.", property.getColumnName()));
391387
}
392-
393388
} catch (SQLException e) {
394389
e.printStackTrace();
395390
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ public void mapNotNeededPrimitiveTypePropertiesToNull() throws SQLException {
128128

129129
}
130130

131+
@Test // DATAJDBC-341
132+
public void mapNotNeededMixedTypePropertiesToNull() throws SQLException {
133+
ResultSet rs = mockResultSet(singletonList("id"), //
134+
ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha");
135+
rs.next();
136+
TrivialMapPropertiesToNullIfNotNeeded extracted = createRowMapper(TrivialMapPropertiesToNullIfNotNeeded.class).mapRow(rs, 1);
137+
138+
assertThat(extracted) //
139+
.isNotNull() //
140+
.extracting(e -> e.id, e -> e.age, e -> e.isSupreme) //
141+
.containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, 0, null);
142+
143+
}
144+
131145
@Test // DATAJDBC-181
132146
public void namingStrategyGetsHonored() throws SQLException {
133147

@@ -480,6 +494,9 @@ static class TrivialMapPropertiesToNullIfNotNeeded {
480494
@Id
481495
Long id;
482496
int age;
497+
String phone;
498+
Boolean isSupreme;
499+
long referenceToCustomer;
483500
}
484501

485502
static class OneToOne {

0 commit comments

Comments
 (0)