| Author |
Not able to save multiple objects
|
Prashanth sirasagi
Greenhorn
Joined: May 06, 2012
Posts: 4
|
|
I have two ojects called company and employee i wanted to save both at one time,im able to store company objects but i m geting an error
Cannot get property 'constraints' on null object for employee..
Can anyone let me know how to save multiple objects?
|
 |
Salil Vverma
Ranch Hand
Joined: Sep 06, 2009
Posts: 219
|
|
Where are you trying to save the object ? In file, in database or at some location in network?
if you are saving the object in database. are you using any ORM tool like Hibernate or using JDBC ?
|
Regards
Salil Verma
|
 |
Prashanth sirasagi
Greenhorn
Joined: May 06, 2012
Posts: 4
|
|
Salil Vverma wrote:Where are you trying to save the object ? In file, in database or at some location in network?
if you are saving the object in database. are you using any ORM tool like Hibernate or using JDBC ?
I wanted to save in database..groovy/grails frame work uses GORM(Hibernate), now im able to save mutilple objects which i am sending through gsp
below how i tried
company and person have one to many relationship
def cname = params.cname
def companyInstance = new Comapany(name:cname)
companyInstance.save()
def name = params.name
def age = params.age
def personInstance = new Person(name:name,age:age)
personInstance.company = companyInstance
personInstance.save()
|
 |
Salil Vverma
Ranch Hand
Joined: Sep 06, 2009
Posts: 219
|
|
have you defined foreign key in database? if yes, have you defined inverse=true in your hibernate mapping?
If you have done both.Can you please show me your mapping file ?
|
 |
Prashanth sirasagi
Greenhorn
Joined: May 06, 2012
Posts: 4
|
|
Hi Salil,
There is no need of maping,just you need to create classes and generate controllers and views,
Just have following code in respective classes
company class:
static hasMany = [employees : Employee]
employee class:
static belongsTo = [company : Company]
For yours reference:grails
Regards
Prashanth
|
 |
 |
|
|
subject: Not able to save multiple objects
|
|
|