2014-06-12 124 views
-1

嘗試將對象保存到我的數據庫時,出現了一個相當奇怪的錯誤。當試圖保存基類對象時,代碼工作的很完善,但現在我試圖保存從基類域類繼承的域類。Grails無法保存對象

這裏是父類:

package com.twc.fatcaone 

class Record { 

long batchID 

} 

而且我想救子類:

package com.twc.fatcaone 

class AccountRecord extends Record { 

    long uniqueId 
    String accountId 
    String type 
    String insurance 
    String currencyType 
    float amount 
    String upSerDel 
    String generalComments 

    static mapping = { 
     collection "accountRecords" 
     database "twcdb" 
} 
} 

在我服務的代碼了試圖做保存:

accountRecordList.each { 

       def accountRecord = new AccountRecord(batchID: params.selectedBatch.id, 
                 uniqueId: it.uniqueId, 
                 accountId: it.accountId, 
                 type: it.type, 
                 insurance: it.insurance, 
                 currencyType: it.currencyType, 
                 amount: it.amount, 
                 upSerDel: it.upSerDel, 
                 generalComments: it.generalComments) 

         if (!AccountRecord.save(flush: true, failOnError: true)) { 
          println "ERROR: Record could not be saved!" 
          def errorValue = AccountRecord.errors 
          println errorValue 
         } 

和試圖保存時出現的錯誤:

/FatcaOne_0/customer/upload - parameters: dataTypegrp: 1 fileTypegrp: 1 No signature of method: com.twc.fatcaone.AccountRecord.save() is applicable for argument types: (java.util.LinkedHashMap) values: [[flush:true, failOnError:true]] Possible solutions: save(), save(), save(boolean), save(java.util.Map), save(boolean), save(java.util.Map). Stacktrace follows: Message: No signature of method: com.twc.fatcaone.AccountRecord.save() is applicable for argument types: (java.util.LinkedHashMap) values: [[flush:true, failOnError:true]] Possible solutions: save(), save(), save(boolean), save(java.util.Map), save(boolean), save(java.util.Map) Line | Method ->> 91 | methodMissing in org.grails.datastore.gorm.GormStaticApi - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 32 | call in org.grails.datastore.gorm.internal.StaticMethodInvokingClosure | 65 | doCall . . . . . . . . . . in com.twc.fatcaone.FileImportService$_$tt__excelAccountFileUpload_closure4 | 53 | $tt__excelAccountFileUpload in com.twc.fatcaone.FileImportService | 119 | upload . . . . . . . . . . in com.twc.fatcaone.CustomerController | 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter | 63 | doFilter . . . . . . . . . in grails.plugin.cache.web.filter.AbstractFilter | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor | 615 | run . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker ^ 744 | run in java.lang.Thread /FatcaOne_0/customer/upload - parameters: dataTypegrp: 1 fileTypegrp: 1 No signature of method: com.twc.fatcaone.AccountRecord.save() is applicable for argument types: (java.util.LinkedHashMap) values: [[flush:true, failOnError:true]] Possible solutions: save(), save(), save(boolean), save(java.util.Map), save(boolean), save(java.util.Map). Stacktrace follows: Message: No signature of method: com.twc.fatcaone.AccountRecord.save() is applicable for argument types: (java.util.LinkedHashMap) values: [[flush:true, failOnError:true]] Possible solutions: save(), save(), save(boolean), save(java.util.Map), save(boolean), save(java.util.Map) Line | Method ->> 91 | methodMissing in org.grails.datastore.gorm.GormStaticApi - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 32 | call in org.grails.datastore.gorm.internal.StaticMethodInvokingClosure | 65 | doCall . . . . . . . . . . in com.twc.fatcaone.FileImportService$_$tt__excelAccountFileUpload_closure4 | 53 | $tt__excelAccountFileUpload in com.twc.fatcaone.FileImportService | 119 | upload . . . . . . . . . . in com.twc.fatcaone.CustomerController | 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter | 63 | doFilter . . . . . . . . . in grails.plugin.cache.web.filter.AbstractFilter | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor | 615 | run . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker ^ 744 | run in java.lang.Thread

+0

新類仍在/ domain /目錄中嗎? – Igor

回答

5

難道不應該是一個小寫字母「A」這個詞AccountRecord只是調用保存功能之前?

+2

這是正確的。對'AccountRecord.save(flush:true,failOnError:true)'的調用被視爲對AccountRecord類的靜態方法調用。應該在'accountRecord'變量上調用一個實例方法。 –

+0

非常感謝。哇,我想我的眼睛盯着代碼太長了。休息時間! –