I have a domain class under the domain folder on Grails.
I have a simple User entity with a String username attribute and i am having problems with some constraints.
class User {
transient springSecurityService
String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static transients = ['springSecurityService']
static constraints = {
username blank: false, unique: true, email: true, size: 4..20
password blank: false
}
static mapping = {
password column: '`password`'
}
Set<Role> getAuthorities() {
UserRole.findAllByUser(this).collect {
it.role
}
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(password) : password
}
}
Constraints like unique, email, and others seems to work correctly but some others like length, size, maxLength, max, min, and validator (custom) seems to be simply ignored (!!) so i am able to save on database objects that violate those constraints.
Any idea what could be the reason?
EDIT: These problems are on the username field ... no thing related password.
EDIT2: I realized the problem does not happens in production mode with MySQL database. It happens at integration test time (GroovyTestCase) using H2 (at least)
EDIT3: Add the full entity code BTW is only an example since I have tested not only with size but also with length, max, min, and others.