grails - 为什么@GrailsCompileStatic允许调用动态GORM查找器而不允许domainClass.withTransaction()?

标签 grails annotations grails-2.5

将@GrailsCompileStatic批注添加到方法或类中可允许使用动态GORM查找器,例如findAllByIdAndProperty()。
但是,添加注释不允许使用domainClass.withTransaction(),这也是GORM AST的补充。为什么?

(使用grails-2.5.3)

更新(16/05/16-10:25 AM)
@ jeff-scott-brown是正确的,它确实可以正常工作,因此以下是@GrailsCompileStatic失败的代码:

...
RestfulApiService service = ServiceUtils.getService(resourceName)
service.resourceClass.withTransaction { /* do something */ }

(resourceClass是Class类型)

错误:
Compilation error: startup failed:
C:\...\myfile.groovy: 100: [Static type checking] - Cannot find matching method java.lang.Class#withTransaction(groovy.lang.Closure). Please check if the declared type is right and if the method exists.
@ line 100, column 13.
           service.resourceClass.withTransaction {
           ^

添加注释后,为什么withTransaction()在这种情况下失败?

最佳答案

Why does @GrailsCompileStatic allow calling dynamic GORM finders but not domainClass.withTransaction()?



是的https://github.com/jeffbrown/withtx/blob/master/grails-app/controllers/demo/DemoController.groovy上的代码进行编译。
import grails.compiler.GrailsCompileStatic

@GrailsCompileStatic
class DemoController {

    def index() {
        Person.withTransaction {
            // ...
        }
        render 'Success!'
    }
}

关于grails - 为什么@GrailsCompileStatic允许调用动态GORM查找器而不允许domainClass.withTransaction()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37126416/

相关文章:

java - Aspectj 匹配切入点而不关心方法级注释参数

grails - Grails网址映射执行错误的操作调用

grails - Grails创建到Webflow的链接

grails - grails bootrun在启动内部tomcat之前挂起

grails - 如何在全局范围内禁用 grails 中的 deepvalidate?

Grails3 generate-all 生成错误的创建 Action 代码

java - Apache Camel : Can I use @Produce without specifying the endpoint uri in the annotation?

Java 互操作 : Apply @JvmName to getters of properties in interface or abstract class

hibernate - 使用左联接的条件不会加载所有具有多个关联的条件

inheritance - 域到域的继承