Skip to content

Commit c59ba06

Browse files
odrotbohmmp911de
authored andcommitted
#2 - EntityRowMapper now prevents constructor argument properties from being read twice.
1 parent 8b006ab commit c59ba06

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/main/java/org/springframework/data/r2dbc/function/convert/EntityRowMapper.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public T apply(Row row, RowMetadata metadata) {
6969

7070
for (JdbcPersistentProperty property : entity) {
7171

72+
if (entity.isConstructorArgument(property)) {
73+
continue;
74+
}
75+
7276
if (property.isCollectionLike()) {
7377
throw new UnsupportedOperationException();
7478
} else if (property.isMap()) {
@@ -105,7 +109,7 @@ private Object readFrom(Row row, JdbcPersistentProperty property, String prefix)
105109
}
106110
}
107111

108-
private Class<?> getType(JdbcPersistentProperty property) {
112+
private static Class<?> getType(JdbcPersistentProperty property) {
109113
return ClassUtils.resolvePrimitiveIfNecessary(property.getActualType());
110114
}
111115

@@ -127,7 +131,9 @@ private <S> S readEntityFrom(Row row, PersistentProperty<?> property) {
127131
ConvertingPropertyAccessor propertyAccessor = new ConvertingPropertyAccessor(accessor, conversions);
128132

129133
for (JdbcPersistentProperty p : entity) {
130-
propertyAccessor.setProperty(p, readFrom(row, p, prefix));
134+
if (!entity.isConstructorArgument(property)) {
135+
propertyAccessor.setProperty(p, readFrom(row, p, prefix));
136+
}
131137
}
132138

133139
return instance;
@@ -142,10 +148,10 @@ private <S> S createInstance(Row row, String prefix, JdbcPersistentEntity<S> ent
142148
@RequiredArgsConstructor
143149
private static class RowParameterValueProvider implements ParameterValueProvider<JdbcPersistentProperty> {
144150

145-
@NonNull private final Row resultSet;
146-
@NonNull private final JdbcPersistentEntity<?> entity;
147-
@NonNull private final ConversionService conversionService;
148-
@NonNull private final String prefix;
151+
private final @NonNull Row resultSet;
152+
private final @NonNull JdbcPersistentEntity<?> entity;
153+
private final @NonNull ConversionService conversionService;
154+
private final @NonNull String prefix;
149155

150156
/*
151157
* (non-Javadoc)

0 commit comments

Comments
 (0)