Source:
<code>public void update(Context context, T dso) throws SQLException, AuthorizeException { if (dso.isMetadataModified()) { Map<MetadataField, Integer> fieldToLastPlace = new HashMap<>(); List<MetadataValue> metadataValues = new LinkedList<>(); if (dso.getType() == Constants.ITEM) { metadataValues = itemService.getMetadata((Item) dso, Item.ANY, Item.ANY, Item.ANY, Item.ANY); } else { metadataValues = dso.getMetadata(); <START> } <END> metadataValues.sort(new Comparator<MetadataValue>() { public int compare(MetadataValue o1, MetadataValue o2) { int compare = o1.getPlace() - o2.getPlace(); if (compare == 0) { if (o1 instanceof RelationshipMetadataValue) { return 1; } else if (o2 instanceof RelationshipMetadataValue) { return -1; } } return compare; } }); for (MetadataValue metadataValue : metadataValues) { if (StringUtils.startsWith(metadataValue.getAuthority(), "virtual::") && ((RelationshipMetadataValue) metadataValue).isUseForPlace()) { int mvPlace = getMetadataValuePlace(fieldToLastPlace, metadataValue); metadataValue.setPlace(mvPlace); String authority = metadataValue.getAuthority(); String relationshipId = StringUtils.split(authority, "::")[1]; Relationship relationship = relationshipService.find(context, Integer.parseInt(relationshipId)); if (relationship.getLeftItem() == (Item) dso) { relationship.setLeftPlace(mvPlace); } else { relationship.setRightPlace(mvPlace); } relationshipService.update(context, relationship); } else if (!StringUtils.startsWith(metadataValue.getAuthority(), "virtual::")) { int mvPlace = getMetadataValuePlace(fieldToLastPlace, metadataValue); metadataValue.setPlace(mvPlace); } } } }</code><technical_language>@paulo-graca in #2332, is a bit strange reference ItemService DSpaceObjectService. sufficient call this.getMetadata(dso, Item.ANY, Item.ANY, Item.ANY, Item.ANY); for objects inheritance do right thing</technical_language>

Target:
public void update(Context context, T dso) throws SQLException, AuthorizeException { if (dso.isMetadataModified()) { Map<MetadataField, Integer> fieldToLastPlace = new HashMap<>(); List<MetadataValue> metadataValues = new LinkedList<>(); if (dso.getType() == Constants.ITEM) { metadataValues = getMetadata(dso, Item.ANY, Item.ANY, Item.ANY, Item.ANY); } else { metadataValues = dso.getMetadata(); } metadataValues.sort(new Comparator<MetadataValue>() { public int compare(MetadataValue o1, MetadataValue o2) { int compare = o1.getPlace() - o2.getPlace(); if (compare == 0) { if (o1 instanceof RelationshipMetadataValue) { return 1; } else if (o2 instanceof RelationshipMetadataValue) { return -1; } } return compare; } }); for (MetadataValue metadataValue : metadataValues) { if (StringUtils.startsWith(metadataValue.getAuthority(), Constants.VIRTUAL_AUTHORITY_PREFIX) && ((RelationshipMetadataValue) metadataValue).isUseForPlace()) { int mvPlace = getMetadataValuePlace(fieldToLastPlace, metadataValue); metadataValue.setPlace(mvPlace); String authority = metadataValue.getAuthority(); String relationshipId = StringUtils.split(authority, "::")[1]; Relationship relationship = relationshipService.find(context, Integer.parseInt(relationshipId)); if (relationship.getLeftItem() == (Item) dso) { relationship.setLeftPlace(mvPlace); } else { relationship.setRightPlace(mvPlace); } relationshipService.update(context, relationship); } else if (!StringUtils.startsWith(metadataValue.getAuthority(), Constants.VIRTUAL_AUTHORITY_PREFIX)) { int mvPlace = getMetadataValuePlace(fieldToLastPlace, metadataValue); metadataValue.setPlace(mvPlace); } } } }