Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to insert a new child record only. One to Many Relation.

 
Ajay Luthria
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a).I have a Trade object which can have multiple status's. One to Many relationship



b.Now,I have inserted a new record with a status of 'New' in the parent(Trade) and child (TradeDetails) tables.
This works fine.(Code is attached below).

c.My Query is:

Now 3 days later, I want to enter a new record in the child table with the same 'parent id'
and status set to 'Verified'.

How can I insert a new record only in the child table with the status set to 'Verified'
and then another with the status set to 'Executed' for the same parent?

i.e 1 Parent - 3 Children entered on different times.

I hope I am clear in my query.

My code to create a new record in Parent and child is below.





 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Load the Parent, add the child to the parent, save them both.

The use of terms "parent" and "child" always seem awkward with their different meaning from parent and child in object models.

-Cameron McKenzie

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic