aspose file tools*
The moose likes Object Relational Mapping and the fly likes Doubt in Mapping( associations of entities) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Doubt in Mapping( associations of entities)" Watch "Doubt in Mapping( associations of entities)" New topic
Author

Doubt in Mapping( associations of entities)

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
In Hibernate we used to map associated entities following
many-many
one-many
many-one
relations.

Is there any simple example based on which we can understand these relations.

with respect to students and courses.
A student has a one-many relationship with courses.
" one student can join in many courses"

with respect to courses,
A single course can contain many students.

I was seeing a database schema diagram to represent these:
There i come across a term multiplicity which confuses me:

Student --->*courses


like wise.
What is multiplicity & how we can conclude whether an association is one-many or many-one or many-many.
Your help is highly appreciated.
Regards.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Any replies?
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
The reason i've posted it that i'm a little bit confused over the term "multiplicity" associated with mapping.
If anybody could provide atleast any good links, I would appreciate it.
Regards.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
any links?
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
multiplicities indicate a cardinality that may exist in the association between two objects.
You have 2 sides in an association and so you can have 2 cardinalities for one association.

To take your example with student and courses.

student (a)*--1(b) course.
This represents an association between student and course. (a) and (b) are the both sides of the association.

To talk about the side (a) you can read say : one course can contain many students. Understand one course object can be linked to several student objects. So side (a) is a one-to-many association from course to student.

To talk about the side (b) you can say : one student can attend one course.
Understand one student object can be link to only one course object.
So side (b) is a one-to-one association from student to course.


Regarding a many-to-many association it is in fact 2 one-to-many associations in both directions.

Unfortunately the hibernate website does not work at the moment for a link...

Hope it will still help
[ October 29, 2008: Message edited by: ntumba lobo ]

SCJP 5 , SCWCD 5, SCEA 5
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Thanks for the reply & it was useful.
But i've a small doubt.
Now if i want to satisfy this condition:

one student can attend many courses but each course should accomodate only one student.
How will you represent the cardinality of this association?
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
student 1--* course
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
student(a) 1--* (b)course


So here with respect to a)
many courses contains one student(since * symbol is on course) i.e many-one relationship between course to student

With respect to b)
one student can attend many courses(since * symbol is on course) i.e. one - many relationship between student to courses .
Is it right?
please clarify.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
sorry,
student-->*courses
With respect to a)
one course contains one student only i.e. one-one association between course and student.
Is it right?
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Any replies ?
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
student-->*courses


In my example student -- course it was a bi-directional association.

In your case student-->*course is a uni-directional association
from student to course that is read as one student can have many courses.
Understand one student object can be linked to many course objects.

Usually when I talk about associations I always precise from object1 to object2 to remove any ambiguities.
[ October 30, 2008: Message edited by: ntumba lobo ]
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
If it is a bi-directional association , then whatever i've specified above is it right?
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
can you precise which association you are talking about ?
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
If there is a bi-directional association between student & courses it will look like this
student(a) 1-->* (b)courses ( one student can enroll in many courses, but each course should contain only one student)

So here with respect to a)
one course can contains one student only i.e. one-one association between course and student.


With respect to b)
one student can attend many courses(since * symbol is on course) i.e. one - many relationship between student to courses .
Is it right?
please clarify.
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
that is right !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in Mapping( associations of entities)