我有一个使用hibernate
.Undergrails 1.3.7
一切正常的 grails 应用程序,但是当我切换到grails 2.0.3
以下问题时:
我无法检查java/src
目录下的唯一字段。如果我尝试使用相同的唯一键添加或更新任何记录,则会出现批量插入错误。
在src/groovy
我创建一个类来检查验证下:
Example: LanguageCommand.groovy
package myproject.command
import org.codehaus.groovy.grails.validation.Validateable;
@Validateable
class LanguageCommand {
String code
String codeDescription
static constraints= {
code(blank:false, maxSize:50)
codeDescription(maxSize:200)
}
}
在src/java
我创建一个类来检查唯一字段
Example: LanguageConstraints.groovy
package myproject.model
constraints = {
code unique: true
}
其中myproject.model
是包含休眠类的包的名称。
笔记: Validation class works fine but the unique one not. i try to add unique constraints to validation class, same error appears
错误:
Error 500: Executing action [save] of controller
[myproject.controller.LanguageController]
caused exception: Runtime error executing action
Servlet: grails
URI: /myproject/grails/language/save.dispatch
Exception Message: Batch entry 0 insert into language
(language_code, code_description, version, id)
values (en, English, 0, 1) was aborted.
Call getNextException to see the cause.
Caused by: Batch entry 0 insert into language
(language_code, code_description, version, id)
values (en, English, 0, 1) was aborted.
Call getNextException to see the cause.
Class: LanguageController
At Line: [125]
Code Snippet:
有什么帮助吗?