I want to design a BOM (bill of material) with CMR entity beans. There will be a class Product.
I thought of a recursive many-to-many relationship
from Product to Product. But can I implement such a relationship with CMR entity beans?
And, what is more, I still have no information about the input factor (how much of Product A is used for Product B).
I thought of a seperate class that represents the N-M relation ship (let's call this one 'InputFactor', any better suggestion are appreciated :-), that holds an amount attribute and a reference to another product entity.
Then I would have a one-to-many relationship from Product to Inputfactor (right?), as I can use many products to build another product. From InputFactor to Product I have a one-to-one relationship. So far, so good.
Let's look at an example:
Call create('P1') for entity Product and get entity instance P1.
Call create('P2') for entity Product and get entity instance P2.
Then create an entity InputFactor and get entity IF1.
Set IF1.prodRef = P2. Set IF1.amount = 4.
Then do P1.addIF(IF1). No problem so far, I guess?!?
What if P2 is used for another product P3.
Call create('P3') for entity Product and get entity instance P3.
Create a new entity InputFactor and get entity IF2.
Set IF2.amount = 2. Now it comes:
Set IF2.prodRef = P2. I do not want to create a new entity here but use P2 again, as it should represent the same product (e.g. a gearwheel). Ok, not the same gearwheel but an instance of the same. Normally I'd create another entity bean for that, but it would represent (at least programmaticaly, not physically) the same product type P2.
But if I use the P2 entity instance for P3, too then CMR would remove P2 from the relationship with IF1. At least I read so in 'Professional EJB'. Is that correct. If yes,
how could I accomplish the required design.
As I said before: Sure, I could create another entity P4 and assign this one to IF2, but P4 would represent exactly the same date (product name, serial number,... ) as P2 does.
This is drivin me nuts. Maybe it's just an error in reasoning.
If anyone can, please help.