繁体   English   中英

Grails 3域类名为“应用程序”的问题

[英]Issues with Grails 3 domain class named “Application”

我有一个旧系统,正在迁移到Grails 3,但遇到了命名约定问题。 我们的表之一称为Application但它也是运行该应用程序的Groovy类的名称。 GORM似乎混淆了这两个类并给出了类型转换错误,这似乎是一个问题。 我试图明确铸造我的Application类中我ApplicationDegree类,试图迫使格姆承认我尝试使用,但没有成功的类。

我知道一个选择是,我可以将域Application类重命名为其他类,然后手动将其映射到适当的数据库表,但是我希望避免这种情况,因为我预见了以后的问题。

因此,除了重命名我的Domain类之外,我如何才能获得Grails / GORM来进行正确的映射。

Grails 3.1.4

码:

ApplicationDegree ad = ApplicationDegree.findById(10);

类:

class ApplicationDegree {

    Boolean isPrimary
    domain.package.Application application
    Degree degree

    static hasMany = [applicationDegreeMajors: ApplicationDegreeMajor,
                      applicationDegreeMinors: ApplicationDegreeMinor]
    static belongsTo = [domain.package.Application, Degree]

    static mapping = {
        version false
        degree column: 'degree_code'
        isPrimary column: 'isPrimary'
    }
}

堆栈跟踪:

ERROR org.grails.spring.beans.factory.OptimizedAutowireCapableBeanFactory - Bean couldn't be autowired using grails optimization: Property 'application' threw exception; nested exception is java.lang.IllegalArgumentException: argument type mismatch
ERROR org.grails.spring.beans.factory.OptimizedAutowireCapableBeanFactory - Retrying using spring autowire
ERROR org.grails.web.errors.GrailsExceptionResolver - IllegalStateException occurred when processing request: [GET] /app4grad_V2/college/applications/
Cannot convert value of type [app4grad.Application] to required type [domain.package.Application] for property 'application': no matching editors or conversion strategy found. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.InstantiationException: Could not instantiate entity:  : domain.package.ApplicationDegree
    at app4grad.college.ApplicationsController$$EPuFyMDe.index(ApplicationsController.groovy:14)
    ... 3 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
    ... 4 common frames omitted
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [app4grad.Application] to required type [domain.package.Application] for property 'application'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [app4grad.Application] to required type [domain.package.Application] for property 'application': no matching editors or conversion strategy found
    ... 4 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot convert value of type [app4grad.Application] to required type [domain.package.Application] for property 'application': no matching editors or conversion strategy found
    ... 4 common frames omitted

我有同样的问题,问题是您使用的是保留名称: https : //grails.org/wiki/Reserved%20Names
使用Intelij Idea,您可以轻松地重命名您的域类,而IDE会为您完成其余工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM