-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Bidirectional One-To-Many relationship
PostPosted: Mon Feb 11, 2013 2:37 pm 
Newbie

Joined: Mon Feb 11, 2013 2:23 pm
Posts: 2
Hi,

In bidirectional One-To-Many relationship, what are the best practices that should be followed? Especially in the case of inserts, who should be the relationship owner, the Many-To-One side or One-To-Many side?

Is there anything like, always One-To-Many side should control the insert/update and if it is in the other way round will there be any performance or any other problems?

Could anybody help me?


Top
 Profile  
 
 Post subject: Re: Bidirectional One-To-Many relationship
PostPosted: Fri Feb 15, 2013 4:12 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
In my view maintaining a one to many relationship for all the child in parent class is more healthy while doing an insert.

What i like in this :

1) you can keep a count on number of child inserted.
2) while updating again you can always look at how many childs were there and how you need to play along with them.

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


Top
 Profile  
 
 Post subject: Re: Bidirectional One-To-Many relationship
PostPosted: Sat Feb 16, 2013 1:03 am 
Newbie

Joined: Mon Feb 11, 2013 2:23 pm
Posts: 2
Thanks a lot Ajith!

I would like to make my question a bit more clear.

I have a parent class, say Purchase, and a purchase has many cheques associated with it. So Purchase has One-To-Many relation ship with Cheque and since it is bidirectional, Cheque has Many-To-One relationship with Purchase. In the queries given below "parent" refers to "Purchase" and child refers to "Cheque".

Case 1:
I have the following queries to make
1. Update some fields in Parent
2. Insert new child records.
3. Delete some child records.
4. Update some child records.

In this case do I have to run separate queries for each step or Can One-To-Many side control all operations?

Case 2:
In this I have queries 2, 3, 4 mentioned in the above case,that means there is no parent row update. What would be the best practice to do the operations?

Case 3:
In this case I have only one child record to insert. What would be the best practice to insert the one child row?

Could anybody help me?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.