borinquenkid commented on code in PR #16522:
URL: https://github.com/apache/grails-core/pull/16522#discussion_r4190732113


##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java:
##########
@@ -46,7 +47,9 @@ public void bind(HibernateToManyProperty property) {
                 .filter(p -> !p.isBidirectional())
                 .count();
 
-        key.setUpdateable(unidirectionalCount <= 1);
+        // The key of a collection of basic values lives in a table of its own 
and Hibernate writes no rows for a
+        // collection whose key is not updatable, so only the key of an entity 
collection is ever made non-updatable.

Review Comment:
   Rewrote the comment in c13815765a: basic and enum collections always keep an 
updatable key, and entity collections go non-updatable only when the owner has 
two or more unidirectional to-many properties (issue 10811).



##########
grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/BasicCollectionKeyPersistenceSpec.groovy:
##########
@@ -0,0 +1,75 @@
+/*
+ *  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 org.grails.orm.hibernate.cfg.domainbinding.secondpass
+
+import grails.gorm.annotation.Entity
+import grails.gorm.tests.HibernateGormDatastoreSpec
+
+/**
+ * Regression test: {@code CollectionKeyColumnUpdater} made the key of a 
collection not updatable when its owner had
+ * more than one unidirectional to-many property. Hibernate then writes no 
rows for the collection, so the elements of a
+ * collection of basic values were silently lost. The key of a collection of 
basic values must stay updatable.
+ */
+class BasicCollectionKeyPersistenceSpec extends HibernateGormDatastoreSpec {
+
+    void setupSpec() {
+        manager.registerDomainClasses(BCKPOneCollection, BCKPTwoCollections)
+    }
+
+    void "the elements of the only collection of an owner are persisted"() {
+        given:
+        BCKPOneCollection owner = new BCKPOneCollection(name: 'one', tags: 
['a', 'b'] as Set)
+        owner.save(flush: true, failOnError: true)
+        session.clear()
+
+        expect:
+        BCKPOneCollection.get(owner.id).tags == ['a', 'b'] as Set
+    }
+
+    void "the elements of each of two collections of an owner are persisted"() 
{
+        given:
+        BCKPTwoCollections owner = new BCKPTwoCollections(name: 'two', tags: 
['a', 'b'] as Set, scores: [1, 2, 3])
+        owner.save(flush: true, failOnError: true)
+        session.clear()
+        BCKPTwoCollections loaded = BCKPTwoCollections.get(owner.id)
+
+        expect:
+        loaded.tags == ['a', 'b'] as Set
+        loaded.scores == [1, 2, 3]

Review Comment:
   The assertion is now size plus `as Set` in c13815765a, since a plain hasMany 
List is not mapped as ordered.



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