File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes Not able to save multiple objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Not able to save multiple objects " Watch "Not able to save multiple objects " New topic
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: 253

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: 253

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to save multiple objects
 
Similar Threads
Circular Reference - Any suggestions?
Java Code -- VB Philosophy
expandable multidimensional ArrayList or Multidimensional Arrays?
Please Help: JList selectable options from 'name' field from each object in a HashMap
Need help on creating tables for a simple scenario