jamesfredley commented on code in PR #16583:
URL: https://github.com/apache/grails-core/pull/16583#discussion_r4407447427


##########
grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/validation/constraints/builtin/UniqueConstraint.groovy:
##########
@@ -133,7 +192,11 @@ class UniqueConstraint extends AbstractConstraint {
             boolean shouldValidate = true
             final ProxyHandler proxyHandler = 
targetEntity.getMappingContext().proxyHandler
             detachedCriteria = detachedCriteria.build {
-                eq(constraintPropertyName, propertyValue)
+                if (propertyValue == null) {
+                    isNull(constraintPropertyName)

Review Comment:
   owner(nullable: true, unique: true) on Neo4j is stored as a relationship. 
isNull looks for a node property, so an asset that has an owner still matches. 
Validating that asset again with owner null is rejected. A null to-one has to 
mean the relationship is absent.



##########
grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/validation/constraints/builtin/UniqueConstraint.groovy:
##########
@@ -100,6 +153,12 @@ class UniqueConstraint extends AbstractConstraint {
             throw new IllegalStateException("Cannot validate object [$target]. 
It is not a persistent entity")
         }
 
+        UniqueNulls nullsReading = 
resolveNulls(GormRegistry.findDatastore(constraintClass))
+        if (propertyValue == null && nullsReading != UniqueNulls.VALUE) {

Review Comment:
   On Oracle, and on Db2 LUW with Hibernate 7, a unique index does not include 
a key that is entirely null. code(nullable: true, unique: true) may be null on 
more than one row. The database reading resolves to VALUE, so validation 
queries IS NULL and rejects the second row. The same happens for a composite 
key whose members are all null. Keep an explicit value reading, and keep the 
database exemption when every constrained value is null.



-- 
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]

Reply via email to