diff --git a/CHANGELOG.md b/CHANGELOG.md index 06642331a6..e55e3ca16d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ None ### Bug fixes -None +* Fix issues with entity view validation errors when using singular collection attributes ### Backwards-incompatible changes diff --git a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractAttribute.java b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractAttribute.java index 2a5dd655e4..ed1eeb94ff 100644 --- a/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractAttribute.java +++ b/entity-view/impl/src/main/java/com/blazebit/persistence/view/impl/metamodel/AbstractAttribute.java @@ -797,25 +797,33 @@ private static boolean isCompatible(javax.persistence.metamodel.Attribute if (updatable) { if (entityAttributeElementType != null) { if (viewAttributeElementType != null) { - // Mapping a plural entity attribute to a plural view attribute + if (singular) { + return viewAttributeType == entityAttributeType && viewAttributeElementType == entityAttributeElementType; + } else { + // Mapping a plural entity attribute to a plural view attribute - // Indexed lists or maps must map to indexed lists or maps again if they want to be updatable - if (attribute instanceof ListAttribute) { - if (!List.class.isAssignableFrom(viewAttributeType)) { - return false; - } - } else if (attribute instanceof MapAttribute) { - if (!Map.class.isAssignableFrom(viewAttributeType)) { + // Indexed lists or maps must map to indexed lists or maps again if they want to be updatable + if (attribute instanceof ListAttribute) { + if (!List.class.isAssignableFrom(viewAttributeType)) { + return false; + } + } else if (attribute instanceof MapAttribute) { + if (!Map.class.isAssignableFrom(viewAttributeType)) { + return false; + } + } else if (!Collection.class.isAssignableFrom(viewAttributeType)) { + // For all other plural attributes, we allow any collection type return false; } - } else if (!Collection.class.isAssignableFrom(viewAttributeType)) { - // For all other plural attributes, we allow any collection type - return false; + return viewAttributeElementType == entityAttributeElementType; } - return viewAttributeElementType == entityAttributeElementType; } else { - // Mapping a plural entity attribute to a singular view attribute - return viewAttributeType == entityAttributeElementType; + if (singular) { + return viewAttributeType == entityAttributeType; + } else { + // Mapping a plural entity attribute to a singular view attribute + return viewAttributeType == entityAttributeElementType; + } } } else { if (viewAttributeElementType != null) {