Discussions

EJB design: How to design a bill of material for EJB (Weird CMR)?

  1. Hi,

    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.

    TIA
    Frank
  2. Why not just have a different sort of entity bean, eg BillOfMat. Lets say it has three fields;

    masterProductID, componentProductID, Quantity.
    (or mPID, cPID and qty for short)

    the primary key is the combination of mPID and cPID.

    Therefore when p1 has p2 as a component product, you have mPID=p1 and cPID-p2. When p3 also has p2 as a component, mPID=p3 and cPID=p2. Everything works ok.

    If using EJB 2.0 make this object a local entity and access via methods on the product home and remote, or via a session bean and JDBC.

    regs
    scot.
  3. Ok, that sounds reasonable, but then I can not use CMR between Product and Product and have to maintain the relationships myself, right?

    TIA
    Frank