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

Commit f26e3b2

Browse files
committed
added a test case that shows #110 is fixed, fix for #110 based on 7.0.x branch
1 parent 447ef9d commit f26e3b2

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

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.tests.GormDatastoreSpec
5+
import grails.gorm.transactions.Rollback
6+
import grails.validation.ValidationException
7+
import spock.lang.Issue
8+
9+
class EmbeddedWithValidationExceptionSpec extends GormDatastoreSpec {
10+
@Override
11+
List getDomainClasses() {
12+
return [DomainWithEmbedded]
13+
}
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+
}

0 commit comments

Comments
 (0)