This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Unable to save data into child table

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I think I am doing something that is very basic, incorrectly.
I have a parent child relation ship in my db and I am trying to save data.Data gets properly saved into parent table but it does not get saved into child table.

I have defined OneToMany relation in parent table and ManyToOne in child table.All of import statements are importing javax.persistence classes (can that be an issue?).

Another thing is that child class is child of two classes(It has two columns that have ManyToOne relations).Is that an issue?

Parent class :-


Child class -


Data should be saved in CustomerCsoProfileMap when data is inserted in CsoProfile.There is no error in logs.Also I see the insert statement for parent class and also the sequencename.nextval for parent class sequence in logs.I do not see any statement in logs for child class at all.
What am I doing wrong?
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What code do you use to persist the objects? Do you get any errors?

Make sure you persist both objects.
Ensure you set both sides of the relationship (add to 1-m and set m-1 back).
 
Jitesh Sinha
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks James.So you mean I have to write code to save data into both Parent and child tables?In that case,what is the use of putting relationship between parent and child(one-to-many and many-to-one)?
Just for getting all children from parent and getting parent from child?
 
Jitesh Sinha
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone please reply to above post?

I have another question as well(somewhat related).
Suppose I have a parent entity and child entity.I have set up one-to-many in parent and many-to-one in child correctly.
Now when setting up parent's attribute,I set the attribute of embedded child object as well.Something like this -

child.setOneAttribute("something") ;
child.setAnother("something") ;


parent.setAttributeA("something") ;
parent.setAttributeB("something") ;
parent.setChildJoinColumn(child) ;
hibernateSession.save(parent) ;//or maybe getHibernateTemplate().save(parent) ;


will it save the data in child entity as well?
Let me know if you want me to clarify anything.

 
reply
    Bookmark Topic Watch Topic
  • New Topic