Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to save multiple objects

 
Prashanth sirasagi
Greenhorn
Posts: 4
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • 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?
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • 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 sirasagi
Greenhorn
Posts: 4
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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 sirasagi
Greenhorn
Posts: 4
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic