From f26e3b228a71d519e84e8709c18791b28e3564b9 Mon Sep 17 00:00:00 2001 From: William Malinowski Date: Sun, 26 Sep 2021 21:49:59 -0400 Subject: [PATCH 1/5] added a test case that shows #110 is fixed, fix for #110 based on 7.0.x branch --- .../AbstractHibernateGormInstanceApi.groovy | 2 +- ...EmbeddedWithValidationExceptionSpec.groovy | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 grails-datastore-gorm-hibernate5/src/test/groovy/grails/gorm/tests/validation/EmbeddedWithValidationExceptionSpec.groovy diff --git a/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/AbstractHibernateGormInstanceApi.groovy b/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/AbstractHibernateGormInstanceApi.groovy index 7dc55401..f8c6c71e 100644 --- a/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/AbstractHibernateGormInstanceApi.groovy +++ b/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/AbstractHibernateGormInstanceApi.groovy @@ -390,7 +390,7 @@ abstract class AbstractHibernateGormInstanceApi extends GormInstanceApi { setObjectToReadOnly target if (entity) { for (Association association in entity.associations) { - if (association instanceof ToOne) { + if (association instanceof ToOne && !association instanceof Embedded) { if(proxyHandler.isInitialized(target, association.name)) { def bean = new BeanWrapperImpl(target) def propertyValue = bean.getPropertyValue(association.name) diff --git a/grails-datastore-gorm-hibernate5/src/test/groovy/grails/gorm/tests/validation/EmbeddedWithValidationExceptionSpec.groovy b/grails-datastore-gorm-hibernate5/src/test/groovy/grails/gorm/tests/validation/EmbeddedWithValidationExceptionSpec.groovy new file mode 100644 index 00000000..daa4b6af --- /dev/null +++ b/grails-datastore-gorm-hibernate5/src/test/groovy/grails/gorm/tests/validation/EmbeddedWithValidationExceptionSpec.groovy @@ -0,0 +1,54 @@ +package grails.gorm.tests.validation + +import grails.gorm.annotation.Entity +import grails.gorm.tests.GormDatastoreSpec +import grails.gorm.transactions.Rollback +import grails.validation.ValidationException +import spock.lang.Issue + +class EmbeddedWithValidationExceptionSpec extends GormDatastoreSpec { + @Override + List getDomainClasses() { + return [DomainWithEmbedded] + } + + @Rollback + @Issue("https://github.com/grails/gorm-hibernate5/issues/110") + void "test validation exception with embedded in domain"() { + when: + new DomainWithEmbedded( + foo: 'not valid', + myEmbedded: new MyEmbedded( + a: 1, + b: 'foo' + ) + ).save(failOnError: true) + + then: + thrown(ValidationException) + } +} + +@Entity +class DomainWithEmbedded { + MyEmbedded myEmbedded + String foo + + static embedded = ['myEmbedded'] + + static constraints = { + foo(validator: { val, self -> + return 'not.valid.foo' + }) + } +} + +class MyEmbedded { + Integer a + String b + + static constraints = { + a(nullable: true) + b(nullalbe: true) + } +} \ No newline at end of file From d284095a5083b9a48a8b822d9153dc444022cd41 Mon Sep 17 00:00:00 2001 From: William Malinowski Date: Mon, 27 Sep 2021 19:59:29 -0400 Subject: [PATCH 2/5] change the test case to extend Specification instead of GormDatastoreSpec --- .../EmbeddedWithValidationExceptionSpec.groovy | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/grails-datastore-gorm-hibernate5/src/test/groovy/grails/gorm/tests/validation/EmbeddedWithValidationExceptionSpec.groovy b/grails-datastore-gorm-hibernate5/src/test/groovy/grails/gorm/tests/validation/EmbeddedWithValidationExceptionSpec.groovy index daa4b6af..6d410aa2 100644 --- a/grails-datastore-gorm-hibernate5/src/test/groovy/grails/gorm/tests/validation/EmbeddedWithValidationExceptionSpec.groovy +++ b/grails-datastore-gorm-hibernate5/src/test/groovy/grails/gorm/tests/validation/EmbeddedWithValidationExceptionSpec.groovy @@ -1,16 +1,16 @@ package grails.gorm.tests.validation import grails.gorm.annotation.Entity -import grails.gorm.tests.GormDatastoreSpec import grails.gorm.transactions.Rollback import grails.validation.ValidationException +import org.grails.orm.hibernate.HibernateDatastore +import spock.lang.AutoCleanup import spock.lang.Issue +import spock.lang.Shared +import spock.lang.Specification -class EmbeddedWithValidationExceptionSpec extends GormDatastoreSpec { - @Override - List getDomainClasses() { - return [DomainWithEmbedded] - } +class EmbeddedWithValidationExceptionSpec extends Specification { + @Shared @AutoCleanup HibernateDatastore hibernateDatastore = new HibernateDatastore(DomainWithEmbedded) @Rollback @Issue("https://github.com/grails/gorm-hibernate5/issues/110") From 9514cbbfe40771339fec93dac6914878a32bccd5 Mon Sep 17 00:00:00 2001 From: William Malinowski Date: Fri, 1 Oct 2021 06:35:50 -0400 Subject: [PATCH 3/5] changed database name used in failing spec --- .../connections/DataSourceConnectionSourceFactorySpec.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grails-datastore-gorm-hibernate5/src/test/groovy/org/grails/orm/hibernate/connections/DataSourceConnectionSourceFactorySpec.groovy b/grails-datastore-gorm-hibernate5/src/test/groovy/org/grails/orm/hibernate/connections/DataSourceConnectionSourceFactorySpec.groovy index 06158a37..149348be 100644 --- a/grails-datastore-gorm-hibernate5/src/test/groovy/org/grails/orm/hibernate/connections/DataSourceConnectionSourceFactorySpec.groovy +++ b/grails-datastore-gorm-hibernate5/src/test/groovy/org/grails/orm/hibernate/connections/DataSourceConnectionSourceFactorySpec.groovy @@ -16,7 +16,7 @@ class DataSourceConnectionSourceFactorySpec extends Specification { when: DataSourceConnectionSourceFactory factory = new DataSourceConnectionSourceFactory() Map config = [ - 'dataSource.url':"jdbc:h2:mem:grailsDB;MVCC=TRUE;LOCK_TIMEOUT=10000", + 'dataSource.url':"jdbc:h2:mem:dsConnDsFactorySpecDb;MVCC=TRUE;LOCK_TIMEOUT=10000", 'dataSource.dbCreate': 'update', 'dataSource.dialect': Oracle8iDialect.name, 'dataSource.properties.dbProperties': [useSSL: false] From 1042f010c843f3568213eb0cba4de84eca3d5b27 Mon Sep 17 00:00:00 2001 From: Puneet Behl Date: Tue, 19 Oct 2021 14:01:26 +0530 Subject: [PATCH 4/5] Only publish test reports when failure --- .github/workflows/gradle.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 2c30fe4f..84e325f6 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -39,14 +39,12 @@ jobs: uses: actions/setup-java@v1 with: java-version: ${{ matrix.java }} - - name: Optional setup step - run: | - [ -f ./setup.sh ] && ./setup.sh || true - name: Run all tests (chromeHeadless) except spring-boot run: ./gradlew -Dgeb.env=chromeHeadless check --no-daemon -x gorm-hibernate5-spring-boot:test - name: Run Spring Boot Tests run: ./gradlew gorm-hibernate5-spring-boot:test --no-daemon - name: Publish Test Report + if: failure() uses: scacap/action-surefire-report@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} From 41f5aa0ba4dc7499db602cede16cf6612b9de4f1 Mon Sep 17 00:00:00 2001 From: Puneet Behl Date: Tue, 19 Oct 2021 14:10:12 +0530 Subject: [PATCH 5/5] Fixed YAML syntax --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 84e325f6..f7d23bfa 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -44,7 +44,7 @@ jobs: - name: Run Spring Boot Tests run: ./gradlew gorm-hibernate5-spring-boot:test --no-daemon - name: Publish Test Report - if: failure() + if: failure() uses: scacap/action-surefire-report@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }}