Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that ValidationException not thrown when Domain has embedded object #399

Merged
merged 5 commits into from Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/gradle.yml
Expand Up @@ -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 }}
Expand Down
Expand Up @@ -390,7 +390,7 @@ abstract class AbstractHibernateGormInstanceApi<D> extends GormInstanceApi<D> {
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)
Expand Down
@@ -0,0 +1,54 @@
package grails.gorm.tests.validation

import grails.gorm.annotation.Entity
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 Specification {
@Shared @AutoCleanup HibernateDatastore hibernateDatastore = new HibernateDatastore(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)
}
}
Expand Up @@ -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]
Expand Down