This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Object Relational Mapping and the fly likes Relevance Of Unique Attribute In Many-To-One relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Relevance Of Unique Attribute In Many-To-One relationship" Watch "Relevance Of Unique Attribute In Many-To-One relationship" New topic
Author

Relevance Of Unique Attribute In Many-To-One relationship

tanu dua
Ranch Hand

Joined: Apr 05, 2004
Posts: 145
Hi,

I was implementing a many-To-One relationship between 2 entities say A and B where A is on Many-Side i.e



So,that means many A can refer to the same B , so the rows of table A will have many similar values of 'id' on which it is joined with table B . But since we are refering the id column as unique that can't be possible , so this seems to be a contradictory to me or am i missing something ?

Please help.


Thanks
Tanu
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Generally while you have a many-to-one relation, the entity which is on the one side will be allowed to have many instances of the other entity which is on the many side.


If 'A' is on the many side and 'B' is on the one side, B is allowed to have many instances of 'A' whereas 'A' can have at the max only one instance of 'B'.


Not aware of how should it be configured in the xml syntax you had given.

HtH.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
tanu dua
Ranch Hand

Joined: Apr 05, 2004
Posts: 145
Thanks Raghavan for an early reply.

Thats what I was thinking , but here in my case the table A is joined with the primary key 'id' of table B and not vice-versa, so that is the only relationship defined and hence the table B can't have multiple instances of A.

So,if I am right if that is the case this many-to-one relationship is turned out to be one-to-one relationship.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344


but here in my case the table A is joined with the primary key 'id' of table B


In this case, table A may have many instances of table B right, provided there is a foreign key relation between table A and B on the id column of table B.

It holds good that table B is on the many side and table A is on the one side. Your xml syntax seems to be correct for what you require.

Just read a bit on Foreign Keys and you may get a clear picture!
[ May 25, 2007: Message edited by: Raghavan Muthu ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Relevance Of Unique Attribute In Many-To-One relationship