首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Grails 2.2.5升级到4.0.11后出现令人费解的验证错误

从Grails 2.2.5升级到4.0.11后出现令人费解的验证错误
EN

Stack Overflow用户
提问于 2021-09-22 18:38:49
回答 1查看 31关注 0票数 0

在Grails 2.2.5中工作了很长时间的一个方法在迁移到4.0.11后崩溃了,在保存时出现了一个验证错误,这个错误对我来说是一个难题。我有一个域类'Decline‘,它有一个属性' user ',它属于域类user。作为保存过程的一部分,我将当前登录的用户分配给此属性:

代码语言:javascript
复制
Decline decline = new Decline()
decline.policy = policy
decline.declineTime = new Date()
decline.field = field
decline.cause = reason
decline.user = User.getUser()
decline.save(flush:true)

这在2.2.5中工作得很好,但现在我得到了以下验证错误:

Field error in object 'myapp.pei.Decline' on field 'user.userType': rejected value [DIRECT_CLIENT]; codes [myapp.User.userType.nullable.error.myapp.pei.Decline.user.userType,myapp.User.userType.nullable.error.user.userType,myapp.User.userType.nullable.error.userType,myapp.User.userType.nullable.error.myapp.UserType,myapp.User.userType.nullable.error,user.userType.nullable.error.myapp.pei.Decline.user.userType,user.userType.nullable.error.user.userType,user.userType.nullable.error.userType,user.userType.nullable.error.myapp.UserType,user.userType.nullable.error,myapp.User.userType.nullable.myapp.pei.Decline.user.userType,myapp.User.userType.nullable.user.userType,myapp.User.userType.nullable.userType,myapp.User.userType.nullable.myapp.UserType,myapp.User.userType.nullable,user.userType.nullable.myapp.pei.Decline.user.userType,user.userType.nullable.user.userType,user.userType.nullable.userType,user.userType.nullable.myapp.UserType,user.userType.nullable,nullable.myapp.pei.Decline.user.userType,nullable.user.userType,nullable.userType,nullable.myapp.UserType,nullable]; arguments [userType,class myapp.User]; default message [Property [{0}] of class [{1}] cannot be null]

关于这一点有两件事令人困惑。首先,也是更重要的是,这似乎是一个保存用户对象的错误。但是为什么它还要尝试保存User对象呢?我已经分配了一个它应该使用的现有User对象。其次,对于字段'user.userType',具体的错误是'rejected value DIRECT_CLIENT‘,但错误消息是该字段不能为空。所以它拒绝了一个值,但告诉我它不能为空!顺便说一下,该值是这样定义的UserType枚举:

代码语言:javascript
复制
public enum UserType {
    ADMIN_USER,ADMIN_OWNER_USER,SUPER_USER,BROKER,DIRECT_CLIENT

}

我想知道从版本2.2.5到版本4(或者可能是3)的什么变化会导致这种情况?

EN

回答 1

Stack Overflow用户

发布于 2021-09-24 14:40:57

在Grails2.x和4.x之间,deepValidate的行为似乎发生了一些变化,导致了这种情况,尽管我不明白为什么关联的User对象的验证应该失败,而实际上可以单独保存它。但是,让我通过这个问题的是在映射块中设置以下内容以进行拒绝:

代码语言:javascript
复制
user cascadeValidate: 'none'

这确保了在保存拒绝对象时,它不会同时尝试验证用户。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69289647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档