0

I am trying to add data to a database, in grails but get this error:

Error 500: Executing action [getData] of controller [mgr.CollectDataEntryController] caused exception: groovy.lang.MissingMethodException: No signature of method: static groovy.lang.MissingMethodException.addToAlumConnectionEducations() is applicable for argument types: (mgr.AlumConnectionEducations) values: [mgr.AlumConnectionEducations : null]

where CollectDataEntryController is the controller doing the work. here is the code snippet from that controller:

saveNewAlum.addToAlumConnectionEducations(new AlumConnectionEducations(alumConnectionsId:connectionId, degree:alumConnectionEduDegree,endDate:alumConnectionEduEndDate,fieldOfStdudy:alumConnectionEduFieldOfStudy,schoolName:alumConnectionEduSchoolName,startDate:alumConnectionEduStartDate))

the domain, AlumConnectionEducations , belongs to a one to many relationship with another domain, AlumConnections, which in turn belongs to a one-to-many relationship with to another domain, alumProfile

to, in my code I first add the domain AlumConnection, which works fine but when i then try to add AlumConnectionEducations i get the above error. anyone have any idea of what i am doing wrong?

thanks jason

    package mgr
    import java.util.Date;
    class AlumConnections  {
String linkedinId
String firstName
String lastName
String headline
String locationName
String locationCode
String industry
    Date dateCreated
Date lastUpdated
long version
static belongsTo = [alumProfile:AlumProfile]
static hasMany = [  
alumConnectionEducations    :   AlumConnectionEducations
 ]
static mapping = {
    cache true

    columns {       
        linkedinId      type:'text'
        firstName       type:'text'
        lastName        type:'text'
        headline        type:'text'
        locationName    type:'text'
        locationCode    type:'text'
        industry        type:'text'

    }
}
static constraints = {  
    linkedinId      (nullable:false, blank:false)
    firstName       (nullable:true)
    lastName        (nullable:true)
    headline        (nullable:true)
    locationName    (nullable:true)
    locationCode    (nullable:true)
    industry        (nullable:true)

}
  }         

in the controller that calls the domains:

  def saveNewAlum = ""
  saveNewAlum = new AlumProfile(firstName:linkedinFirstName, lastName:linkedinLastName, dob:newDate,industry:linkedinIndustry, oAuthToken:oAuthtoken, secretKey:secretKey)

  saveNewAlum.addToAlumConnections(new   AlumConnections(linkedinId:connectionId,firstName:connectionFName, lastName:connectionLName, headline:connectionHeadline, locationName:connectionLocationname, locationCode:connectionLocationCode,industry:connectionIndustry))

The above code works fine and saves to the MySQL database. its only when i try to create saveNewAlum.addToAlumConnectionEducations that i get the error

5
  • Can you post your code for AlumConnections? Commented Jul 21, 2011 at 18:56
  • i added it to my above question, as i couldnt seem to add it in a comment. Commented Jul 21, 2011 at 19:08
  • Can you also add the code that creates the saveNewAlum variable? Have you verified that it's truly an instance of AlumConnections? Commented Jul 21, 2011 at 22:23
  • thank you for your reply. i added the saveNewAlum code to the first post. yes, i have verified that the saveNewAlum works fine as it saves to the MySQL db without error Commented Jul 21, 2011 at 23:59
  • maybe whats wrong is this: i have a one-to-many relationship. to save it, i first create the parent (saveNewAlum) then, to add its various children (those objects that belong to it) i do this: saveNewAlum.addToAlumConnections(new AlumConnections(...)) but the problem is that i need to know how to take one of the children and create a one-to-many with it and another object (alumConnectionEducations). So, would i have to do something like this: saveNewAlum.AlumConnections.addToAlumConnectionEducations(new AlumConnections.Educations(...)) ? Commented Jul 22, 2011 at 0:20

1 Answer 1

1

well, it took all day but i got it. so, my assumption seemed to be right, it was the one-to-many with a one-to-many that was causing the problem. here's how i fixed it. The domains were right the way i had it. in the controller: first, i create the main parent:

         saveNewAlum=new AlumProfile(firstName:linkedinFirstName, lastName:linkedinLastName, dob:newDate, industry:linkedinIndustry, oAuthToken:oAuthtoken, secretKey:secretKey)

then, i create the object to be added to the child:

     myConnection= new AlumConnections(linkedinId:connectionId,firstName:connectionFName,lastName:connectionLName,headline:connectionHeadline,locationName:connectionLocationname, locationCode:connectionLocationCode,industry:connectionIndustry)

then, i save the child to the parent:

    saveNewAlum.addToAlumConnections(myConnection)

then, i create the object to save to the child's child:

  newConnectionEdu=  new AlumConnectionEducations(
              degree:alumConnectionEduDegree,
              endDate:alumConnectionEduEndDate,
              fieldOfStudy:alumConnectionEduFieldOfStudy,
              schoolName:alumConnectionEduSchoolName,
              startDate:alumConnectionEduStartDate)

then, finally, i add the child to the child:

 myConnection.addToAlumConnectionEducations(newConnectionEdu)

and that is how you add a child to a child!

Sign up to request clarification or add additional context in comments.

1 Comment

you may also play around cascading for same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.