Since inheriting EJBs is not safe, is it possible to simply build your 
object model as if you weren't using EJB, then build one entity bean for 
each persistent object, and some number of session beans to act as the 
interface?  The entity beans would be a kind of struct that your 'real' 
object used essentially as its persistent member variables.

Example:
Let's say you want to model a simple system using EJB.  You build:

ShapeMaker (stateless session bean)
Member functions
    ObjID makeTriangle(Point2d a, Point2d b, Point2d c)
    ObjID makeCircle(Point2d origin, float radius)
    void drawShape(long shapeID)

Shape (entity bean)
Member functions
    void draw()
    //assume standard no-arg ejbCreate and corresponding Home

Triangle extends Shape (entity bean)
Member functions
    void draw()
    TrianglePK ejbCreate(Point2d a, Point2d b, Point2d c)
    //assume home & PK to go with this
Member data
    float ax;  //(x coord of Point2d a)
    float ay;  //(y coord of Point2d a)
    float bx;  //(x coord of Point2d b)
    float by;  //(y coord of Point2d b)
    float cx;  //(x coord of Point2d c)
    float cy;  //(y coord of Point2d c)

Circle extends Shape (entity bean)
Member functions
    void draw()
    CirclePK ejbCreate(Point2d origin, float radius)
    //assume home & PK to go with this
Member data
    float origX;  //(x coord of origin)
    float origY;  //(y coord of origin)
    float radius;

This can't really be done reliably, if I understand correctly, because 
inheritance is not supported by EJB 1.2.  (Please disregard the lack of 
applicability of EJB to this problem (who wants to draw objects on some 
remote server?), it's just meant to be illustrative.)  However, will the 
following work reliably:

(same ShapeMaker as above)

Shape (non-EJB class)
    //same as above, but just use standard constructor instead of ejbCreate

Triangle extends Shape (non-EJB class)
    //same methods as above, but just use standard constructor instead of 
ejbCreate
Member data
    TriangleData data;

TriangleData (entity bean)
    //no methods except EJB methods
Member data
    //as per Triangle from example above

Circle extends Shape (non-EJB class)
    //same methods as above, but just use standard constructor instead of 
ejbCreate
Member data
    CircleData data;

CircleData
    //no methods except EJB methods
Member data
    //as per Circle from example above

Now that I've written three pages of example, the question is:  Is this 
reliable?  Is this a common design pattern when implementing EJBs?

My first concern was that I didn't know how the application would know which 
calls would happen in which transactions.  My conclusion after some thought 
was that JBoss likely has a mapping from Thread objects to UserTransaction 
objects or some equivalent to track the association of a transaction with a 
call stack.  Can someone tell me if that is correct, or if not, what the 
mechanism is to associate a transaction with a call stack in JBoss?

Thanks much for your time,
Bobby Martin
Cosm development team
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com



--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
List Help?:          [EMAIL PROTECTED]

Reply via email to