• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Not able to save multiple objects

 
Greenhorn
Posts: 4
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Prashanth sirsagi
Greenhorn
Posts: 4
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 sirsagi
Greenhorn
Posts: 4
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic