2016-08-18 52 views
2

我有一个遗留系统,我正在迁移到Grails 3,但我遇到了一个命名约定问题。我们的其中一个表名为Application,但它也是运行该应用程序的Groovy类的名称。似乎有一个问题,GORM混淆了2个类并给出了类型转换错误。我曾尝试明确地在我的ApplicationDegree课中投入我的Application课程,试图强制GORM识别我尝试使用的课程,但没有成功。Grails 3域名为“Application”的问题

我知道一个选择是我可以将我的域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 
+0

尝试使用导入来代替;添加'import domain.package.Application'并将类'domain.package.Application'更改为类Application中的'Application' –

+0

@BurtBeckwith抱歉是我已经尝试过,但是当'import'不起作用时,我尝试了直接类型转换。它们都不工作。我已经删除它不仅因为它没有工作,而且因为我的Intellij IDE说它是一个未使用的导入。 –

回答