gpt4 book ai didi

Grails removeFrom() 问题

转载 作者:行者123 更新时间:2023-12-02 02:25:08 25 4
gpt4 key购买 nike

在我的申请人域类中,我有以下内容:

static hasMany = [recommendationFiles:ApplicantFile]
static mapping = {recommendationFiles joinTable: [name:"LETTER_FILES", key: "APPLICANT_ID", column: "LETTER_ID"]}

当我执行以下操作时:

    def applicant = Applicant.findByENumber(session.user.eNumber)
def applicantFiles = applicant.recommendationFiles
println applicantFiles
applicantFiles.each {
applicant.removeFromRecommendationFiles(it)
}
applicant.save(flush:true)

我将此视为一个错误,这对我来说毫无意义:

| Error 2015-04-08 10:41:59,570 [http-bio-8080-exec-10] ERROR errors.GrailsExceptionResolver  - ConcurrentModificationException occurred when processi
ng request: [POST] /scholarshipsystem/specialized/index - parameters:
_action_reUpload: Re-Upload
Stacktrace follows:
Message: null
Line | Method
->> 793 | nextEntry in java.util.HashMap$HashIterator
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 828 | next in java.util.HashMap$KeyIterator
| 106 | reUpload in scholarshipSystem.SpecializedController$$EP9HMKbd
| 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 918 | run . . . in ''
^ 662 | run in java.lang.Thread

最佳答案

有几种方法可以实现这一点。一种方法是将列表转换为数组并对其进行迭代。

def list = applicantFiles.toArray()
list.each {
applicant.removeFromRecommendationFiles(it)
}

另一种方式,如果您只是删除整个集合,那么...

applicant.recommendationFiles*.delete()
applicant.recommendationFiles.clear()

关于Grails removeFrom() 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29544973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com