This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes How to insert a  new child record only. One to Many Relation. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to insert a  new child record only. One to Many Relation." Watch "How to insert a  new child record only. One to Many Relation." New topic
Author

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

Ajay Luthria
Greenhorn

Joined: Jul 15, 2009
Posts: 5
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

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

 
wood burning stoves
 
subject: How to insert a new child record only. One to Many Relation.
 
Similar Threads
Why ConstraintViolationException is generated?
Hibernate Query by Example
what changes should i made in save method in one-to-many relationships
Parent-Child Relationship Problem
One to Many relationship Error. Please guide.