DATAJDBC-374 - Polishing.
Clarified the effects of collections on nullable embedded entities. Original pull request: #154.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user