Inheritance and non-ejb objects in EntityBeans....

Discussions

EJB design: Inheritance and non-ejb objects in EntityBeans....

  1. Inheritance and non-ejb objects in EntityBeans.... (4 messages)

    I'm looking at taking advantage of inheritance in my enitiy beans. Now I have read posting '1230' and it's cousins so I'm fairly sure I know HOW to do it properly. My question is, what if my superclass is not extending EJBObject? For instance, I have a baseclass Car, which is never instantiated as an EJB but represents all the common properties and attributes of all Cars. This information would be stored in a table called Car. I then have two concrete derived classes, SportsCar and Truck, which contain different attributes and properties from each other. How do I properly manage the persistance of the superclasss fields in the derived classes?


    eg>

    class Car implements Serializable{
    //car stuff goes here
        int size;
        String company;
    //etc

    }

    class SportsCar extends Car implements EntityBean{
          int topspeed;
          boolean convertible;

    //etc
    }

    class Truck extends Car implements EntityBean{
          int loadCapacity;
          boolean fourWD;

    //etc
    }

    Since ONLY SportscCars and Trucks are EntityBeans and will be created by clients (NOT Cars), how does each ejb manage the fields of its superclass, either through BMP or CMP? Especially since Car data will be stored in a main table and the extra data for the different car types will be stored in another table (possibly as multiple, separate records).


    Hope this gets you all thinking...Hope I've stated it clearly enough...

    Mike

  2. Mike,

    With BMP, it would be your responsibility as the developer to persist the data to the correct tables. So, you would need to write the JDBC calls that persist the items in both the Car class and the SportsCar or Truck class. For CMP, I don't think there is an EJB Container out there that will be able to do what you want. You might want to look at CocoBase (www.thoughtinc.com) or other similar product, which integrate with the EJB container to provide more complex CMP capabilites. I'm not sure whether any of these products will be able to do what you're asking, because I haven't tried it, but they're probably your best bet.

    Steve Finck
    Corporate Technology Partners
    www.ctpartners.com
  3. Steve,

    Thanks...that's what I figured. Now my real fun can begin...my ejbStore() for these beans can't update the database, but insert a new record with a recursive pointer back to the previous record for audit trail purposes. So I would then need to change the database record (and thus the PK object) associated with the ejb object reference I have to the new one I just created with the ejbStore() call (got that?). Any ideas on this front?

    I'm messing around with an Oracle DB and Weblogic trying to prototype this now so any help would be appreciated. I'll be sure to post if I come up with the answer

    Mike
  4. Mike,

    What you're thinking about doing might get extremely messy, and I'm not sure if it's even possible. What I would suggest is using a Session EJB as a Facade to your entity beans. Instead of updating the existing entity bean, have the session ejb create a new entity bean with the updated information.

    Steve Finck
    Corporate Technology Partners
    www.ctpartners.com
  5. Steve,
    I am looking into doing just that as well...luckily concurrency is not currently an issue so I can use the Details Object pattern for displaying the information in the client and updating

    I'll let you know how it works out

    Mike