Q: Different results with hasMany relation in Grails I have two classes namely UserSurvey and SurveyResponseSet. UserSurvey has many SurveyResponseSet.
class UserSurvey {
    Survey survey
    List responses = []
    String surveyCompleted = ''
    .
    .
    .   
    static hasMany = [
        responses: SurveyResponseSet
    ]

    static mapping = {
        responses cascade: 'delete'
    }
}


class SurveyResponseSet {
    UserSurvey userSurvey
    Integer sumWeight = 0
    .
    .
    .
    static constraints = {
        sumWeight nullable:true, default: 0
    }
}

To get the list of SurveyResponseSet I was doing before UserSurveyObject.responses and it was working fine until now. Today it started throwing error while iterating over the list.
I am using Grails 2.4.0. I tried clean, CleanAll but it didn't resolved.
I looked further and found that UserSurveyObject.responses was giving some extra results in list that were null. Here is the result of the console :
UserSurvey uSurvey = UserSurvey.get(1437);
List<SurveyResponseSet> listFromSurvey = uSurvey.responses;
List<SurveyResponseSet> listUsingSurvey = SurveyResponseSet.findAllByUserSurvey(uSurvey); 

println listFromSurvey; 
println listUsingSurvey;

[null, nexant.SurveyResponseSet : 9788, nexant.SurveyResponseSet : 9789, nexant.SurveyResponseSet : 9793, nexant.SurveyResponseSet : 9794, nexant.SurveyResponseSet : 9795, null, nexant.SurveyResponseSet : 9874, nexant.SurveyResponseSet : 9875, nexant.SurveyResponseSet : 9879, nexant.SurveyResponseSet : 9880, nexant.SurveyResponseSet : 9881, nexant.SurveyResponseSet : 9882, null, nexant.SurveyResponseSet : 9884, nexant.SurveyResponseSet : 9885]


[nexant.SurveyResponseSet : 9795, nexant.SurveyResponseSet : 9794, nexant.SurveyResponseSet : 9793, nexant.SurveyResponseSet : 9789, nexant.SurveyResponseSet : 9788, nexant.SurveyResponseSet : 9885, nexant.SurveyResponseSet : 9884, nexant.SurveyResponseSet : 9882, nexant.SurveyResponseSet : 9881, nexant.SurveyResponseSet : 9880, nexant.SurveyResponseSet : 9879, nexant.SurveyResponseSet : 9875, nexant.SurveyResponseSet : 9874]

I don't understand from where it has been fetching three extra objects that are null.

A: In regards to the null you could try :
class SurveyResponseSet {
    UserSurvey userSurvey
    Integer sumWeight = 0
    .
    .
    .
     static mapping = { 
       userSurvey ignoreNotFound : true
     }

    static constraints = {
        sumWeight nullable:true, default: 0
    }
}

See if that removes the null elements from the list
