Skip to content

Commit

Permalink
[Blazebit#1111] Fix issues with validation error when using updatable…
Browse files Browse the repository at this point in the history
… singular collection attribute
  • Loading branch information
beikov committed Jun 9, 2020
1 parent 7b10b15 commit acf93b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ None

### Bug fixes

None
* Fix issues with entity view validation errors when using singular collection attributes

### Backwards-incompatible changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit acf93b6

Please sign in to comment.