Events 在grails域类中,BeforeInsert和BeforeUpdate被触发两次
我在应用程序中使用的是grails 2.1.0版,我的域类中有一个before insert,它对密码进行编码,如下所示 包com.valuelabs.bets.security 第二类用户{ 临时安全服务Events 在grails域类中,BeforeInsert和BeforeUpdate被触发两次,events,grails,persistence,grails-domain-class,Events,Grails,Persistence,Grails Domain Class,我在应用程序中使用的是grails 2.1.0版,我的域类中有一个before insert,它对密码进行编码,如下所示 包com.valuelabs.bets.security 第二类用户{ 临时安全服务 String username String password String emailId String mobileNumber String position boolean enabled boolean accountExpired boolean accountLocked bo
String username
String password
String emailId
String mobileNumber
String position
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
boolean firstTimeLogin
String userstatus
String userRole
Date activateDate
Date expireDate = new Date()
Audit audit
static embedded = ['audit']
static mapping = {
password column: '`password`'
sort "username"
}
def beforeInsert() {
println "in before insert"
encodePassword()
}
def beforeUpdate() {
println "in before update"
if (isDirty('password')) {
encodePassword()
}
audit.lastUpdated = new Date()
}
protected void encodePassword() {
println " Before ========================> "+ password
if(springSecurityService){
password = springSecurityService.encodePassword(password)
}
println " springSecurityService "+ springSecurityService +" password "+password
}
Set<SecRole> getAuthorities() {
SecUserSecRole.findAllBySecUser(this).collect { it.secRole } as Set
}
String toString(){
username
}
static transients = ['userstatus','userRole']
现在的问题是,当我保存实例时,密码被编码了两次
请让我知道grails版本是否有任何问题,如果有,请让我知道正确的版本或可能的解决方案。能否向我们展示您的DataSource.groovy文件?请注意,GORM事件的触发次数与您应用程序中的数据源相同。能否从controller和您编写保存代码并提供域结构的服务。我已更改了域控制器的代码。请查看itI。当定义了多个数据源且域类中包含
datasource“ALL”
时,我看到了相同的行为。即使它只插入一个数据源,它也会在之前调用重新插入多次。
if (!secUserInstance.save(flush:true)) {
println "13"
//secUserInstance.errors.allErrors.each { println it }
render(view: "create", model: [secUserInstance: secUserInstance,curRole:""])
return
}