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

Cannot define default mapping/constraints #179

Open
2 of 4 tasks
jamesdh opened this issue Feb 4, 2021 · 3 comments
Open
2 of 4 tasks

Cannot define default mapping/constraints #179

jamesdh opened this issue Feb 4, 2021 · 3 comments

Comments

@jamesdh
Copy link
Contributor

jamesdh commented Feb 4, 2021

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a fresh app w/ groovy/GORM
  2. Create a generic GORM domain class
  3. Create a src/main/resources/application.groovy file w/ the following added:
import static grails.gorm.hibernate.mapping.MappingBuilder.orm

grails.gorm.default.mapping = orm {
    id {
        generator('org.hibernate.id.enhanced.SequenceStyleGenerator')
        params([prefer_sequence_per_entity: true])
    }
}

// or try it with a more traditional style...
//grails.gorm.default.mapping = orm {
//    id([
//            generator: 'org.hibernate.id.enhanced.SequenceStyleGenerator',
//            params:[prefer_sequence_per_entity: true]
//    ])
//}

//grails.gorm.default.mapping = {
//    id {
//        generator = 'org.hibernate.id.enhanced.SequenceStyleGenerator'
//        params = [prefer_sequence_per_entity: true]
//    }
//}

Expected Behaviour

The default mapping would be applied to the domain, and a sequence would be generated based on the domain classes name.

Actual Behaviour

When defining the mapping via the MappingBuilder DSL, it does not appear to ever be executed, and when defining the mapping using the traditional closure, it fails due to static type checking, e.g.

Script1.groovy: 19: [Static type checking] - Cannot find matching method Script1#id(groovy.lang.Closure). Please check if the declared type is correct and if the method exists.

Environment Information

  • Operating System: MacOS 10.15.7
  • Micronaut Version: 2.3.1
  • JDK Version: 11
@jameskleeh
Copy link
Contributor

Try setting the system property micronaut.groovy.config.compileStatic to false

@jameskleeh jameskleeh added closed: notabug The issue is not a bug type: docs and removed closed: notabug The issue is not a bug labels Feb 11, 2021
@jameskleeh
Copy link
Contributor

Seems that system property isn't documented. Please verify that it works and if so, we can leave this issue open to document it

@jamesdh
Copy link
Contributor Author

jamesdh commented Feb 11, 2021

Can confirm, disabling compileStatic on configs via gradle e.g.

tasks {
    named<JavaExec>("run") {
        systemProperty("micronaut.groovy.config.compileStatic", "false")
    }
}

...and then using the closure form of grails.gorm.default.mapping does work e.g.

grails.gorm.default.mapping = {
     id generator: 'org.hibernate.id.enhanced.SequenceStyleGenerator', params: [prefer_sequence_per_entity: true]
}

Using the MappingBuilder.orm static method does not:

grails.gorm.default.mapping = orm {
    id {
        generator('org.hibernate.id.enhanced.SequenceStyleGenerator')
        params([prefer_sequence_per_entity: true])
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants