diff --git a/orm/src/main/java/org/hibernate/tool/internal/reveng/strategy/OverrideRepository.java b/orm/src/main/java/org/hibernate/tool/internal/reveng/strategy/OverrideRepository.java index 1fcbd8cecf..bbeb6137d1 100644 --- a/orm/src/main/java/org/hibernate/tool/internal/reveng/strategy/OverrideRepository.java +++ b/orm/src/main/java/org/hibernate/tool/internal/reveng/strategy/OverrideRepository.java @@ -278,6 +278,28 @@ protected boolean excludeTable(TableIdentifier identifier) { } } + private void combineAttributeMaps(final Map source, final Map destination) { + for(Map.Entry attributeEntry : destination.entrySet()){ + // Matching key in both reveng strategy and overrideRepository. Need to combine. + if(source.containsKey(attributeEntry.getKey())) { + MetaAttribute overrideMeta = source.get(attributeEntry.getKey()); + // Add any values to those generated in the RevengStrategy for a combined result. + overrideMeta.getValues().forEach(value -> { + if(!attributeEntry.getValue().getValues().contains(value)){ + attributeEntry.getValue().addValue((String)value); + } + }); + } + } + // Now move over attributes from overrideRepository that were not present + // in the value generated by revengStrategy + for(Map.Entry attributeEntry : source.entrySet()){ + if(!destination.containsKey(attributeEntry.getKey())){ + destination.put(attributeEntry.getKey(),attributeEntry.getValue()); + } + } + } + public void addTableFilter(TableFilter filter) { tableFilters.add(filter); } @@ -290,11 +312,34 @@ public boolean excludeTable(TableIdentifier ti) { } public Map tableToMetaAttributes(TableIdentifier tableIdentifier) { - return OverrideRepository.this.tableToMetaAttributes(tableIdentifier); + Map metaAttributeMap = super.tableToMetaAttributes(tableIdentifier); + if(null != metaAttributeMap && !metaAttributeMap.isEmpty()) { + Map configFileAttributeMap = + OverrideRepository.this.tableToMetaAttributes(tableIdentifier); + // If there are attributes from both RevengStrategy and OverrideRepository, combine them together. + if(null != configFileAttributeMap && !configFileAttributeMap.isEmpty()) { + OverrideRepository.this.combineAttributeMaps(configFileAttributeMap, metaAttributeMap); + } + // Return combined map + return metaAttributeMap; + } + else return OverrideRepository.this.tableToMetaAttributes(tableIdentifier); } public Map columnToMetaAttributes(TableIdentifier tableIdentifier, String column) { - return OverrideRepository.this.columnToMetaAttributes(tableIdentifier, column); + Map metaAttributeMap = super.columnToMetaAttributes(tableIdentifier, column); + if(null != metaAttributeMap && !metaAttributeMap.isEmpty()) { + Map configFileAttributeMap = + OverrideRepository.this.columnToMetaAttributes(tableIdentifier, column); + + // If there are attributes from both RevengStrategy and OverrideRepository, combine them together. + if(null != configFileAttributeMap && !configFileAttributeMap.isEmpty()) { + OverrideRepository.this.combineAttributeMaps(configFileAttributeMap, metaAttributeMap); + } + // Return combined map + return metaAttributeMap; + } + else return OverrideRepository.this.columnToMetaAttributes(tableIdentifier, column); } public boolean excludeColumn(TableIdentifier identifier, String columnName) {