DATACMNS-1296 - PersistentPropertyPathAccessor now properly handles intermediate nulls when setting values.

We now use a dedicated GetOptions instance for the lookup of the parent path in case SetOptions is defined to skip nulls so that the lookup does not fail if the parent path contains a null value.
This commit is contained in:
Oliver Drotbohm
2020-08-06 08:50:20 +02:00
parent cdd8359103
commit c99f2c9459
2 changed files with 27 additions and 3 deletions

View File

@@ -86,6 +86,20 @@ class SimplePersistentPropertyPathAccessorUnitTests {
}).doesNotThrowAnyException();
}
@Test // DATACMNS-1296
void skipsIntermediateNullsWhenSettingNestedValues() {
CustomerWrapperWrapper wrapper = new CustomerWrapperWrapper(null);
PersistentPropertyPathAccessor<CustomerWrapperWrapper> accessor = getAccessor(wrapper);
PersistentPropertyPath<SamplePersistentProperty> path = context
.getPersistentPropertyPath("wrapper.customer.firstname", CustomerWrapperWrapper.class);
assertThatCode(() -> {
accessor.setProperty(path, "Dave", AccessOptions.defaultSetOptions().skipNulls());
}).doesNotThrowAnyException();
}
private void assertFirstnamesSetFor(Customers customers, String path) {
PersistentPropertyPath<SamplePersistentProperty> propertyPath = context.getPersistentPropertyPath(path,
@@ -124,4 +138,9 @@ class SimplePersistentPropertyPathAccessorUnitTests {
static class CustomerWrapper {
Customer customer;
}
@AllArgsConstructor
static class CustomerWrapperWrapper {
CustomerWrapper wrapper;
}
}