これが私の単純なドメインクラスです:
package projectmanagement
class Project {
String Name
static constraints = {
}
}
コントローラーにメソッドを保存します (足場を使用して生成):
def save() {
def projectInstance = new Project(params)
if (!projectInstance.save(flush: true)) {
projectInstance.errors.allErrors.each {
println it
}
render(view: "create", model: [projectInstance: projectInstance])
return
}
flash.message = message(code: 'default.created.message', args: [message(code: 'project.label', default: 'Project'), projectInstance.id])
redirect(action: "show", id: projectInstance.id)
}
プロジェクトを保存しようとすると、次のエラーが表示されます。
Field error in object 'projectmanagement.Project' on field 'name': rejected value [null]; codes [projectmanagement.Project.name.nullable.error.projectmanagement.Project.name,projectmanagement.Project.name.nullable.error.name,projectmanagement.Project.name.nullable.error.java.lang.String,projectmanagement.Project.name.nullable.error,project.name.nullable.error.projectmanagement.Project.name,project.name.nullable.error.name,project.name.nullable.error.java.lang.String,project.name.nullable.error,projectmanagement.Project.name.nullable.projectmanagement.Project.name,projectmanagement.Project.name.nullable.name,projectmanagement.Project.name.nullable.java.lang.String,projectmanagement.Project.name.nullable,project.name.nullable.projectmanagement.Project.name,project.name.nullable.name,project.name.nullable.java.lang.String,project.name.nullable,nullable.projectmanagement.Project.name,nullable.name,nullable.java.lang.String,nullable]; arguments [name,class projectmanagement.Project]; default message [Property [{0}] of class [{1}] cannot be null]
SQL ログには次のように表示されます。
Hibernate: select this_.id as id0_0_, this_.version as version0_0_, this_.name as name0_0_ from project this_ limit ?
Hibernate: select count(*) as y0_ from project this_
params.dump() は以下を示します:
<org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap@6715e66f request=org.apache.catalina.core.ApplicationHttpRequest@2a6e8f nestedDateMap=[:] wrappedMap=[name:kkjkj, create:Create, action:save, controller:project]>
Grails 2.2 と Intellij Idea IDE を使用しています。過去5〜6か月間Grailsを使用していませんが、以前に同じ問題が発生したことを思い出せません。