Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Doubt in Mapping( associations of entities)

 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any replies?
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any links?
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
student 1--* course
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any replies ?
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is a bi-directional association , then whatever i've specified above is it right?
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you precise which association you are talking about ?
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that is right !
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic