Hi,
My Grails app has a User class and a Role class. The User class has an authorities property which holds the roles assigned to that user, e.g.
class User {
static hasMany = [authorities: Role]
// This method is called automatically after a user is inserted
def afterInsert() {
this.authorities.size()
}
}
If I create a user and assign them a role, a NullPointerException is thrown from the GORM event method afterInsert(), because authorities is null.
If I comment out afterInsert() the user is saved correctly along with the assigned role. Is there some reason why I can't access associations from GORM event methods. Is is possible that this event is fired after the User row is inserted, but before the row is added to the User-Role join table?
Thanks,
Don