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


##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/CreateKeyForProps.java:
##########
@@ -59,23 +66,38 @@ public void createKeyForProps(HibernatePersistentProperty 
grailsProp, String pat
         PropertyConfig mappedForm = grailsProp.getMappedForm();
 
         if (mappedForm.isUnique() && mappedForm.isUniqueWithinGroup()) {
+            if (metadataCollector.isInSecondPass()) {
+                createKeyForGroup(grailsProp, path, table, columnName, 
mappedForm);
+            } else {
+                metadataCollector.addSecondPass(persistentClasses ->
+                        createKeyForGroup(grailsProp, path, table, columnName, 
mappedForm));
+            }
+        }
+    }
 
-            List<Column> keyList = new ArrayList<>();
-            keyList.add(new Column(columnName));
-            List<String> propertyNames = mappedForm.getUniquenessGroup();
-            GrailsHibernatePersistentEntity owner = 
grailsProp.getHibernateOwner();
-            for (String propertyName : propertyNames) {
-                HibernatePersistentProperty otherProp = 
owner.getHibernatePropertyByName(propertyName);
-                if (otherProp == null) {
-                    throw new MappingException(
-                            owner.getJavaClass().getName() + " references an 
unknown property " + propertyName);
-                }
+    private void createKeyForGroup(
+            HibernatePersistentProperty grailsProp, String path, Table table, 
String columnName, PropertyConfig mappedForm) {
+        List<Column> keyList = new ArrayList<>();
+        keyList.add(new Column(columnName));
+        List<String> propertyNames = mappedForm.getUniquenessGroup();
+        GrailsHibernatePersistentEntity owner = grailsProp.getHibernateOwner();
+        for (String propertyName : propertyNames) {
+            HibernatePersistentProperty otherProp = 
owner.getHibernatePropertyByName(propertyName);
+            if (otherProp == null) {
+                throw new MappingException(
+                        owner.getJavaClass().getName() + " references an 
unknown property " + propertyName);
+            }
+            List<ColumnConfig> columns = 
otherProp.getHibernateMappedForm().getColumns();
+            if (columns.isEmpty()) {
+                columns = Collections.singletonList(null);
+            }
+            for (ColumnConfig column : columns) {
                 String otherColumnName =
-                        
columnNameForPropertyAndPathFetcher.getColumnNameForPropertyAndPath(otherProp, 
path, null);
+                        
columnNameForPropertyAndPathFetcher.getColumnNameForPropertyAndPath(otherProp, 
path, column);

Review Comment:
   Fixed in 23d85bcca0. Group members go through 
getColumnNamesForPropertyAndPath and addGroupColumns: composite user type 
attributes, then each configured column, otherwise the single default.



##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/CreateKeyForProps.java:
##########
@@ -59,23 +66,38 @@ public void createKeyForProps(HibernatePersistentProperty 
grailsProp, String pat
         PropertyConfig mappedForm = grailsProp.getMappedForm();
 
         if (mappedForm.isUnique() && mappedForm.isUniqueWithinGroup()) {
+            if (metadataCollector.isInSecondPass()) {
+                createKeyForGroup(grailsProp, path, table, columnName, 
mappedForm);
+            } else {
+                metadataCollector.addSecondPass(persistentClasses ->

Review Comment:
   Fixed in 23d85bcca0. createKeyForProps and createKeyForColumns both use 
createKeyWhenReady, so the key waits for the second pass unless it is already 
in that pass.



##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/util/CreateKeyForProps.java:
##########
@@ -35,17 +38,21 @@ public class CreateKeyForProps {
 
     private final ColumnNameForPropertyAndPathFetcher 
columnNameForPropertyAndPathFetcher;
     private final UniqueKeyForColumnsCreator uniqueKeyForColumnsCreator;
+    private final InFlightMetadataCollector metadataCollector;
 
-    public CreateKeyForProps(ColumnNameForPropertyAndPathFetcher 
columnNameForPropertyAndPathFetcher) {
-        this.columnNameForPropertyAndPathFetcher = 
columnNameForPropertyAndPathFetcher;
-        this.uniqueKeyForColumnsCreator = new UniqueKeyForColumnsCreator();
+    public CreateKeyForProps(

Review Comment:
   Fixed in 23d85bcca0. The one-argument CreateKeyForProps constructor remains. 
A null collector creates the key immediately, and CompositeUserTypeBinder 
passes the collector.



##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/ColumnBinder.java:
##########
@@ -65,14 +66,16 @@ public ColumnBinder(
         this.indexBinder = indexBinder;
     }
 
-    public ColumnBinder(PersistentEntityNamingStrategy namingStrategy, Dialect 
dialect) {
+    public ColumnBinder(
+            PersistentEntityNamingStrategy namingStrategy, Dialect dialect, 
MetadataBuildingContext metadataBuildingContext) {

Review Comment:
   Fixed in 23d85bcca0. The extra ColumnBinder constructor is gone. The 
context-first 8.0.x constructor remains, and a null context supplies a null 
collector.



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