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 d开发者_运维技巧oing 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
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!
精彩评论