Browse Source

DATAJDBC-374 - Polishing.

Clarified the effects of collections on nullable embedded entities.

Original pull request: #154.
pull/156/head
Jens Schauder 7 years ago
parent
commit
ebe76a0c7f
  1. 8
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java
  2. 3
      src/main/asciidoc/jdbc.adoc

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

@ -378,11 +378,15 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc @@ -378,11 +378,15 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
ReadingContext<?> newContext = extendBy(property);
if(OnEmpty.USE_EMPTY.equals(property.findAnnotation(Embedded.class).onEmpty())) {
if(shouldCreateEmptyEmbeddedInstance(property) || newContext.hasInstanceValues(idValue)) {
return newContext.createInstanceInternal(idValue);
}
return newContext.hasInstanceValues(idValue) ? newContext.createInstanceInternal(idValue) : null;
return null;
}
private boolean shouldCreateEmptyEmbeddedInstance(RelationalPersistentProperty property) {
return OnEmpty.USE_EMPTY.equals(property.findAnnotation(Embedded.class).onEmpty());
}
private boolean hasInstanceValues(@Nullable Object idValue) {

3
src/main/asciidoc/jdbc.adoc

@ -332,6 +332,9 @@ public class MyEntity { @@ -332,6 +332,9 @@ public class MyEntity {
<1> Shortcut for `@Embedded(onEmpty = USE_NULL)`.
====
Embedded entities containing a `Collection` or a `Map` will always be considered non empty since they will at least contain the empty collection or map.
Such an entity will therefore never be `null` even when using @Embedded(onEmpty = USE_NULL).
[[jdbc.entity-persistence.state-detection-strategies]]
=== Entity State Detection Strategies

Loading…
Cancel
Save