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
嘗試使用導入來代替;添加'import domain.package.Application'並將類'domain.package.Application'更改爲類Application中的'Application' –
@BurtBeckwith抱歉是我已經嘗試過,但是當'import'不起作用時,我嘗試了直接類型轉換。它們都不工作。我已經刪除它不僅因爲它沒有工作,而且因爲我的Intellij IDE說它是一個未使用的導入。 –