Xilang
Xilang

Reputation: 1513

Grails validation goes into a loop and never breaks

I have a class User which has a validation rule like:

def readyUserCount = User.createCriteria().count({
    eq('userStatus',UserStatus.Ready)                   
})
if(100 > readyUserCount){
    return true
}

When validated, it will count existing rows in the DB. The issue is when I update a object, it will trigger validation, validation will trigger flush, flush will trigger validation, validation will trigger flush, and never break up. (If I'm inserting instead of updating this issue does not occur). Can anyone help me?

Upvotes: 1

Views: 362

Answers (1)

Victor Sergienko
Victor Sergienko

Reputation: 13495

Try withNewSession():

def count = User.withNewSession{ User.countByUserStatus(UserStatus.Ready) }

Upvotes: 2

Related Questions