Grails无法保存对象

时间:2014-06-12 18:09:01

标签: hibernate 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

1 个答案:

答案 0 :(得分:5)

不应该是一个小写的' a'在调用保存函数之前的单词AccountRecord中?