我被扔进了一个现有的 grails 项目,我遇到的一个问题是,当批量保存一些东西时,我得到了错误:Cannot set readonly property: programId
这是我的导致错误的保存片段
// Create a batch
def batch = new Batch()
batch.name = session.batch_name
batch.startDate = new Date()
batch.endDate = new Date()
batch.programId = 120
if(batch.save()) {
...
}
这是我的批处理域类
class Batch extends AbstractDomainObject{
String name
Date startDate
Date endDate
String comments
StatusType currentStatus
static belongsTo = [program:Program]
static constraints = {
name(blank:false,maxSize:100)
startDate()
endDate()
comments (nullable:true, maxSize:DEFAULT_SIZE_OF_COMMENTS)
currentStatus(nullable:true)
}
static transients= ["currentStatus"]
static mapping = {
id column:'batch_id', generator:'sequence', params:[sequence:'sq_batch']
currentStatus column:'status_type_id'
program column:'program_id'
statuses sort:'statusDate'
startDate type:'date'
endDate type:'date'
}
public String toString(){
return name
}
public Date createdDate(){
Date date=null
if(this?.statuses?.size()>0){
this?.statuses.each{
if(it.status.value==SystemConstants.STATUS_PENDING){
date = it.statusDate
}
}
}
return date
}
}
为什么它不让我设置programId
?