Scienze  
Syllabus ItalianoSyllabus IngleseindexlogoutArea Personale UNITN
Sistemi distribuiti: design Forum del Corso Messaggi del Thread
 
Sistemi distribuiti: design - Forum del Corso
Messaggi del Thread

Autore Messaggio
m.bernabe
Thread
  Post Postato: 9 febbraio 2005
   Titolo: a many-to-many relation - adding new fields
 

Hi,
I have a question: can we adding a new field in a table generated for a many-to-many relation?

Example:
a box contains many product.
a product can be contained in many boxes.
I want to keep track of the number of each product in each box.

Each table is generated using Entity Beans and the relation uses Collection to access data.

Table_prod:
id 

Table_box:
id

Table_boxid_prodid:
idprod
idbox
amount_of_product

Tank you!
afogarolli
  Post Postato: 10 febbraio 2005
   Titolo: Re: a many-to-many relation - adding new fields
 

Hi!
You can not have attributes of a relationship with CMP, because the relationship table; it's trasparent for you, it's managed totaly by the container. For each association between product and box the container creates a row in the association table(so if you have 3 product in the same box you will get 3 rows in the n-m table).
From this point of view it would have no sense to have a ridondant field in the association table with the quantity that you have to update in all the records when a new association is made.
Your problem (how to know the number of product in a box) could be solve with a "select count() where product = x and box= y" using jdbc or you may have to reconsider you design choices.
If you put a cmr field in box bean (for example Collection getProducts()), you coud navigate the relationship and than with a Collection.size() you will get the number of generic products in the box, if you need to know the number of product X in the box you must interate the collection and check the product type (of course this operation colud be really costy if you have a lot of products in a box).
 
Progetto eLeaf
Contact eLeaf team