Grails无法保存对象

Ano*_*man -1 grails hibernate

我试图将对象保存到我的数据库时得到一个相当奇怪的错误.在尝试保存基类对象时,代码已经完成了,但现在我正在尝试保存从基类域继承的域类.

这是父类:

package com.twc.fatcaone

class Record {

long batchID

}
Run Code Online (Sandbox Code Playgroud)

和我想要保存的子类:

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"
}
}
Run Code Online (Sandbox Code Playgroud)

我的服务中的代码正在尝试进行保存:

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
                       }
Run Code Online (Sandbox Code Playgroud)

和尝试进行保存时得到的错误:

/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

小智 5

在调用save函数之前,不应该在AccountRecord这个单词中使用小写的'a'吗?

  • 那是正确的.调用`AccountRecord.save(flush:true,failOnError:true)`被视为`AccountRecord`类的静态方法调用.应该在`accountRecord`变量上调用一个实例方法. (2认同)