The short answer is "No, you can't have true polymorphism in EJB." Other
than your idea about the session bean, you could write your client in
such a way that it always _knows_ which subtype it wants, or write your
entity using the State/Strategy pattern, so that it exposes all possible
operations, then delegates to a 'State' object internally for variable
behavior. The entity could choose (in ejbLoad, maybe ejbActivate) which
State subclass to instantiate based on the discriminator's value.
Good luck,
danch
Davide Mora wrote:
> Hi!
>
> i'm trying to reuse a legacy database (from COBOL)
> with entity beans (BMP).
> The database describe a structure like this: Product,
> Share extends Product, Warrant extends Product etc.,
> all this described in only one table (with more than
> 200 fields!!).
> In many articles i read is possible inherit entity
> beans, i did it, and seems work, at least with JBoss,
> what i'm not able to do i query the base class
> (Product) and load the right entity depending on a
> discriminator field.
> For example, if i query the Product, i get only
> instances of Product also when is Share or Warrant,
> example:
>
> productHome.findByPriceRange(a,b);
> ...
> while( itr.hasNext() )
> {
> if ( itr.next() instanceof Product )
> {
> // Wrong! Was a Share!
> }
> }
>
> I tought also about write a session bean that query
> the database, read the primary key and the
> discriminator and calls findByPrimaryKey() on the
> home.
> It's the only way or there is something better?
> Any help or link to articles/examples is welcome!
>
> In EJB2.0 will be the same, or there will be an easier
> way for handle this problem? (very common case in OOP
> i think)
>
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user