codeconsole commented on issue #15680:
URL: https://github.com/apache/grails-core/issues/15680#issuecomment-4553160245
## Updated Root Cause
The actual root cause is in
`DefaultMappingConfigurationBuilder.getProperties()`:
```java
Map<String, Property> getProperties() {
if (!target.propertyConfigs.isEmpty()) {
properties.putAll(target.propertyConfigs) // ← overwrites
mapping-set properties
}
return properties
}
```
The constraint evaluation populates `Entity.propertyConfigs` (via
`Entity.methodMissing`) with a fresh property instance containing only
constraint values (e.g., `unique=true`). When `getProperties()` merges via
`putAll`, it overwrites the mapping-configured property that has `index=true`
and `indexAttributes={unique:true}`.
### Fix
Change `putAll` to `putIfAbsent` semantics so mapping-configured properties
are preserved:
```groovy
Map<String, Property> getProperties() {
if (!target.propertyConfigs.isEmpty()) {
for (Map.Entry entry : target.propertyConfigs.entrySet()) {
if (!properties.containsKey(entry.key)) {
properties.put(entry.key, entry.value)
}
}
}
return properties
}
```
Branch with fix + test: `fix/constraint-overwrites-mapping-index` on `7.2.x`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]