I got thrown into an existing grails project and one of the issues i'm having is that when saving something a batch, i get the error: Cannot set readonly property: programId
Here's my save snippet that causes the error
// 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()) {
...
}
Here's my batch domain class
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
}
}
Why does it not let me set the programId
?