• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on UniDirectional Association

 
Nandu itha
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the Unidirectional Assciation can there be a mutiplicity on both the sides?
(0..*) (1..*)
A_________________>B, Can this be possible?

If so can the class A can have the reference of B and can the class B can have reference of "A". Help would be greately appreciated.

Thanks

 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, It will require a mapping table.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nandu itha wrote:With the Unidirectional Assciation can there be a mutiplicity on both the sides?
(0..*) (1..*)
A_________________>B, Can this be possible?

Yes.

Consider the case of a non-homeless person and an address.

Each person must have at least one address associated with them, but they may have multiple addresses associated with them.

Addresses do not have to have any any people associated with them, but they may have many people associated with them.

Nandu itha wrote:If so can the class A can have the reference of B and can the class B can have reference of "A".

You do not normally want to do this. No matter how many individual fields you allocate in A for references to B you will eventually run out. And the same with references to A in B. Going back to my example of people and addresses - if each person has 5 fields dedicated to a reference to an address, what happens when you want to associate them with a sixth address?

As Rishi states, you will require an intermediate (join) table that just contains pair references. If you want to find all the references to B then you do a search in the join table for all the B records that have a corresponding A record.

Most ORM systems handle these join tables for you automatically.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic