Polishing.
Refactored code to better use existing code.
Original Pull Request:
@@ -351,32 +351,24 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
@Nullable
private Object readEmbeddedEntityFrom(@Nullable Object idValue, RelationalPersistentProperty property) {
- ReadingContext<?> ctx = extendBy(property);
- return hasInstanceValues(property, ctx) ? ctx.createInstanceInternal(idValue) : null;
+ ReadingContext<?> newContext = extendBy(property);
+ return newContext.hasInstanceValues(idValue) ? newContext.createInstanceInternal(idValue) : null;
}
- private boolean hasInstanceValues(RelationalPersistentProperty property, ReadingContext<?> ctx) {
+ private boolean hasInstanceValues(Object idValue) {
- RelationalPersistentEntity<?> persistentEntity = getMappingContext()
- .getPersistentEntity(property.getTypeInformation());
-
- PersistentPropertyPathExtension extension = ctx.path;
+ RelationalPersistentEntity<?> persistentEntity = path.getLeafEntity();
for (RelationalPersistentProperty embeddedProperty : persistentEntity) {
+ // if the embedded contains Lists, Sets or Maps we consider it non-empty
if (embeddedProperty.isQualified() || embeddedProperty.isReference()) {
return true;
}
- try {
- if (ctx.getObjectFromResultSet(extension.extendBy(embeddedProperty).getColumnName()) != null) {
+ if (readOrLoadProperty(idValue, embeddedProperty) != null) {
return true;
}
- } catch (MappingException e) {
- if (ctx.getObjectFromResultSet(extension.extendBy(embeddedProperty).getReverseColumnNameAlias()) != null) {
- return true;
- }
- }
}
return false;
