> CompanyHome.findPublicShareCompanies() will return a collection of ICompany
> not of IPublicShareCompany and the container will invoke business methods
> of CompanyImpl, not of  PublicShareCompanyImpl. I don't see any easy
> workaround (maybe I missed something) to insure that the finder method
> will return a IPublicShareCompany or to invoke PublicShareCompanyImpl
> methods from CompanyImpl keeping the security and transaction context.

I'm assuming you are doing CMP on top of RDBMS, that Company and
PublicShareCompany map to the same table with field marking which type
of company. I can make a different assumption, but EJB is defined to
support RDBMS primarily.

Depending on your CMP engine, when your run findPublicShareCompanies two
things are going to happen:

1. The CMP engine has no clue that the same table can map to two
different objects, it can only return a Company object. Period. EJB has
to live with this limitation.

2. The CMP engine knows that certain records map to a different object
(beats me how), and return a Company or PublicShareCompany object. You
then need to do the proper casting.

3. The CMP engine is using some form of query that can dictate which
object to return. OQL can allow you that.

For the sake of simplicity the EJB finder of a given entity bean will
always attempt to retrieve beans of that type. This is the finder
specified in the EJB specs, it is not the only form of finder you can
have.

Alternatively, you can call
PublicShareCompany.findPublicShareCompanies() and get the proper result,
or you can use a server-specific engine to map
Company.findPublicShareCompanies() into a finder that return an entity
other than the type of the entity on which the finder was called.

However, if you choose the latter case you EJB server will have to
contain a sophisticated CMP persistence engine, which cannot be said of
all EJB servers out there. Your beans will then work with one product,
but break with another.

I guess the conclusion of this argument is that the problem is rooted in
the lowest-common-denominator approach of the EJB specs, and that
approach guarantees portability across multiple servers, even if some
are better than others. It does not, however, prevent a server from
offering you better support, assuming you only deploy on these specific
servers.

arkin

----------------------------------------------------------------------
Assaf Arkin                                    http://www.exoffice.com
CTO, Exoffice Technologies                       http://www.exolab.org


>
> Do you have any hint on how to implement these polymorphic finders?
> The only way I see is to have a specialized SessionBean that does the
> find on the base class bean, check some fields in the returned entity
> bean and then replace the object in the collection by the derived class
> when it found an object that should be from a derived class.
>
> Collection c = BaseClassHome.findBySomeCriteria( xxx );
> Collection replacement = new SomeConcreteCollection();
> for (Iterator i = c.iterator(); i.hasMore();)
> {
>     BaseClass base = (BaseClass) i.next();
>     if (  DerivedClass.SPECIFIC_VALUE.equals(base.getTheProperty()))
>     {
>          i.remove();
>          replacement.add( DerivedClass.findByPrimaryKey(base.getPrimaryKey()));
>     }
> }
> c.addAll(replacement);
> return c;
>
> The problem with that solution is that you have to change the find methods
> everytime you add a new class in the hierarchy.  You also must put some field
> in the base class to keep track of the actual class of the object.
>
> Do you have cleaner suggestions?
>
> Benoit Tremblay (Clea informatique)
> at Ericsson Research Canada
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to