Copilot commented on code in PR #16720:
URL: https://github.com/apache/grails-core/pull/16720#discussion_r4343848845
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/CreateKeyForProps.java:
##########
@@ -70,9 +72,15 @@ public void createKeyForProps(HibernatePersistentProperty
grailsProp, String pat
throw new MappingException(
owner.getJavaClass().getName() + " references an
unknown property " + propertyName);
}
- String otherColumnName =
-
columnNameForPropertyAndPathFetcher.getColumnNameForPropertyAndPath(otherProp,
path, null);
- keyList.add(new Column(otherColumnName));
+ List<ColumnConfig> columns =
otherProp.getHibernateMappedForm().getColumns();
+ if (columns.isEmpty()) {
+ columns = Collections.singletonList(null);
+ }
+ for (ColumnConfig column : columns) {
+ String otherColumnName =
+
columnNameForPropertyAndPathFetcher.getColumnNameForPropertyAndPath(otherProp,
path, column);
+ keyList.add(new Column(otherColumnName));
+ }
Review Comment:
`otherProp.getHibernateMappedForm()` is now dereferenced unconditionally. If
`getHibernateMappedForm()` can ever return null (which previously would not
matter), this will throw an NPE during metadata binding/startup. To preserve
the prior “fallback” behavior robustly, treat a null mapped form (or null
columns list) the same as “no explicit columns” and proceed with the
singleton-null column fallback path.
##########
grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/EnumUniqueGroupAssociationSpec.groovy:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package grails.gorm.tests
+
+import grails.gorm.annotation.Entity
+import grails.gorm.hibernate.HibernateEntity
+import groovy.transform.EqualsAndHashCode
+import spock.lang.Issue
+
+@Issue('https://github.com/apache/grails-core/issues/16713')
+class EnumUniqueGroupAssociationSpec extends HibernateGormDatastoreSpec {
+
+ void setupSpec() {
+ manager.registerDomainClasses(EnumUniqueCompositeParent,
EnumUniqueCompositeChild)
+ }
+
+ void "an enum unique group includes every mapped column of a composite
parent"() {
+ given:
+ def table =
datastore.metadata.getEntityBinding(EnumUniqueCompositeChild.name).table
+
+ expect:
+ table.uniqueKeys.values().collect { it.columns*.name.toSet() } ==
+ [['child_state', 'parent_code', 'parent_revision'] as Set]
Review Comment:
The unique-key assertion is brittle because it requires the table to have
exactly one unique key with exactly that set of columns. If additional unique
constraints are introduced later (even unrelated), this test will fail despite
the intended key still being present. Prefer asserting that
`table.uniqueKeys.values()` contains *at least one* key with the expected
column set (similar to the foreign-key assertion).
##########
grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForPropsSpec.groovy:
##########
@@ -19,6 +19,7 @@
package org.grails.orm.hibernate.cfg.domainbinding
+import org.grails.orm.hibernate.cfg.PropertyConfig
Review Comment:
This spec introduces `import org.grails.orm.hibernate.cfg.PropertyConfig`
but still references `org.grails.orm.hibernate.cfg.PropertyConfig`
fully-qualified later. Using one style consistently (either the import
everywhere or fully-qualified everywhere) reduces noise and makes the test
easier to scan.
##########
grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForPropsSpec.groovy:
##########
@@ -193,7 +197,9 @@ class CreateKeyForPropsSpec extends Specification {
def uniqueKeyCreator = Mock(UniqueKeyForColumnsCreator)
def subject = new CreateKeyForProps(columnNameFetcher,
uniqueKeyCreator)
def owner = Mock(GrailsHibernatePersistentEntity)
- def otherProp = Mock(HibernatePersistentProperty)
+ def otherProp = Mock(HibernatePersistentProperty) {
+ getHibernateMappedForm() >> new PropertyConfig()
+ }
def mappedForm = Mock(org.grails.orm.hibernate.cfg.PropertyConfig) {
Review Comment:
This spec introduces `import org.grails.orm.hibernate.cfg.PropertyConfig`
but still references `org.grails.orm.hibernate.cfg.PropertyConfig`
fully-qualified later. Using one style consistently (either the import
everywhere or fully-qualified everywhere) reduces noise and makes the test
easier to scan.
##########
grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/CreateKeyForPropsSpec.groovy:
##########
@@ -165,7 +167,9 @@ class CreateKeyForPropsSpec extends Specification {
def uniqueKeyCreator = Mock(UniqueKeyForColumnsCreator)
def subject = new CreateKeyForProps(columnNameFetcher,
uniqueKeyCreator)
def owner = Mock(GrailsHibernatePersistentEntity)
- def otherProp = Mock(HibernatePersistentProperty)
+ def otherProp = Mock(HibernatePersistentProperty) {
+ getHibernateMappedForm() >> new PropertyConfig()
+ }
def mappedForm = Mock(org.grails.orm.hibernate.cfg.PropertyConfig) {
Review Comment:
This spec introduces `import org.grails.orm.hibernate.cfg.PropertyConfig`
but still references `org.grails.orm.hibernate.cfg.PropertyConfig`
fully-qualified later. Using one style consistently (either the import
everywhere or fully-qualified everywhere) reduces noise and makes the test
easier to scan.
--
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]