Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit c7fb100

Browse files
authored
Merge pull request #399 from grails/billgonemad-110-fix-7.0.x
Test that ValidationException not thrown when Domain has embedded object
2 parents 447ef9d + 41f5aa0 commit c7fb100

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ jobs:
3939
uses: actions/setup-java@v1
4040
with:
4141
java-version: ${{ matrix.java }}
42-
- name: Optional setup step
43-
run: |
44-
[ -f ./setup.sh ] && ./setup.sh || true
4542
- name: Run all tests (chromeHeadless) except spring-boot
4643
run: ./gradlew -Dgeb.env=chromeHeadless check --no-daemon -x gorm-hibernate5-spring-boot:test
4744
- name: Run Spring Boot Tests
4845
run: ./gradlew gorm-hibernate5-spring-boot:test --no-daemon
4946
- name: Publish Test Report
47+
if: failure()
5048
uses: scacap/action-surefire-report@v1
5149
with:
5250
github_token: ${{ secrets.GITHUB_TOKEN }}

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/AbstractHibernateGormInstanceApi.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ abstract class AbstractHibernateGormInstanceApi<D> extends GormInstanceApi<D> {
390390
setObjectToReadOnly target
391391
if (entity) {
392392
for (Association association in entity.associations) {
393-
if (association instanceof ToOne) {
393+
if (association instanceof ToOne && !association instanceof Embedded) {
394394
if(proxyHandler.isInitialized(target, association.name)) {
395395
def bean = new BeanWrapperImpl(target)
396396
def propertyValue = bean.getPropertyValue(association.name)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package grails.gorm.tests.validation
2+
3+
import grails.gorm.annotation.Entity
4+
import grails.gorm.transactions.Rollback
5+
import grails.validation.ValidationException
6+
import org.grails.orm.hibernate.HibernateDatastore
7+
import spock.lang.AutoCleanup
8+
import spock.lang.Issue
9+
import spock.lang.Shared
10+
import spock.lang.Specification
11+
12+
class EmbeddedWithValidationExceptionSpec extends Specification {
13+
@Shared @AutoCleanup HibernateDatastore hibernateDatastore = new HibernateDatastore(DomainWithEmbedded)
14+
15+
@Rollback
16+
@Issue("https://github.com/grails/gorm-hibernate5/issues/110")
17+
void "test validation exception with embedded in domain"() {
18+
when:
19+
new DomainWithEmbedded(
20+
foo: 'not valid',
21+
myEmbedded: new MyEmbedded(
22+
a: 1,
23+
b: 'foo'
24+
)
25+
).save(failOnError: true)
26+
27+
then:
28+
thrown(ValidationException)
29+
}
30+
}
31+
32+
@Entity
33+
class DomainWithEmbedded {
34+
MyEmbedded myEmbedded
35+
String foo
36+
37+
static embedded = ['myEmbedded']
38+
39+
static constraints = {
40+
foo(validator: { val, self ->
41+
return 'not.valid.foo'
42+
})
43+
}
44+
}
45+
46+
class MyEmbedded {
47+
Integer a
48+
String b
49+
50+
static constraints = {
51+
a(nullable: true)
52+
b(nullalbe: true)
53+
}
54+
}

grails-datastore-gorm-hibernate5/src/test/groovy/org/grails/orm/hibernate/connections/DataSourceConnectionSourceFactorySpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DataSourceConnectionSourceFactorySpec extends Specification {
1616
when:
1717
DataSourceConnectionSourceFactory factory = new DataSourceConnectionSourceFactory()
1818
Map config = [
19-
'dataSource.url':"jdbc:h2:mem:grailsDB;MVCC=TRUE;LOCK_TIMEOUT=10000",
19+
'dataSource.url':"jdbc:h2:mem:dsConnDsFactorySpecDb;MVCC=TRUE;LOCK_TIMEOUT=10000",
2020
'dataSource.dbCreate': 'update',
2121
'dataSource.dialect': Oracle8iDialect.name,
2222
'dataSource.properties.dbProperties': [useSSL: false]

0 commit comments

Comments
 (0)