Hibernate Inserting relationships


EJB design: Hibernate Inserting relationships

  1. Hibernate Inserting relationships (5 messages)

    I am having a 1-to-many relationship btw Parent and child class....In the parent class i am something like private Set children = new HashSet(); public void setChildren(Set children)... public Set getChildren() The parent hbm mapping file has: -------------------------------------------------------------------------------- While inserting records in the db, my code is: code: -------------------------------------------------------------------------------- Parent p = new Parent(); Set child1 = new HashSet(); ....populate child 1 data Set child 2 = new HashSet(); ....populate child 2 data p.getChildren().add(child1); p.getChildren().add(child2); session.save(p); -------------------------------------------------------------------------------- The above code inserts successfully in the parent db but does not insert in the child table Any ideas?....I have tried "inverse=true" as well...Do i need to define a Many-to-one in child as well?

    Threaded Messages (5)

  2. hi......[ Go to top ]

    Hi, put cascade="all" in u r tag this may be helpful regards, Digesh
  3. Re:[ Go to top ]

    I tried doing it...It does show the insert statement...However i could see that after insert in the child table, it is now also trying to update the child table....
  4. Re:[ Go to top ]

    try inverse = true in child hbm file.. Regards, Rakesh.
  5. Re:[ Go to top ]

    try inverse = true in child hbm file..

    Sorry I ment child definition in parent eg: Regards, Rakesh.
  6. Thanks Rajesh...The inserts are now working as expected without explicitly saving the child....I was just wondering whether loading (Select query) the parent object will load the children as well ?