If you consider this from a design pattern perspective, I think it makes a
lot more sense.
The Remote and Bean implementations are classes that are tied specifically
to functionality, and therefore they support inheritance well. The home
interface, on the other hand, is a factory object. It does not lend itself
well to inheritance unless you have designed it to be very non-specific.
This is even more true when you consider what the application server is
going to have to do when it receives the home interface. It will attempt to
create a valid factory object based on what it finds. The logic to create a
factory on one object is simple, and this should work. But consider the
logic for creating a factory with inheritance. The potential branches are
enormous, and most vendors won't have gone to the time and trouble to
implement them. So, it's in your best interest to stay away from this.
In the only case where I have needed a factory that 'knows' about the parent
and the children (in the case where the factory will generate PK's to
multiple child types and return them as an array of parent keys) I used a
stateless session bean. Since the session bean is not involved in the
inheritance, it does not have any issues 'knowing' about both parents and
all children.
Jonathan Baker
Internet Applications Division
Sybase, Inc.
Shelly Aggrawal wrote:
>
> Hi All,
> I know that we have visited Inheritance a lot of times in this mailing
> list.. but the following seems to be still unconfirmed:
>
> Suppose i have a parent entitybean, say ParentBean. The RI and Home I Parent
> and ParentHome. the PK type is ParentPK...
> I understand that the only way to inherit an entity bean is by inheriting
> the interfaces and classes separately. So, i have a child which is
>
> public interface Child extends Parent{
> pubic void AChildMethod();
> }
>
> public class ChildBean extends ParentBean{}
>
> I do not see a problem with inheriting the remote interface and with the
> corresponding methods in the bean class. But can I, and is it valid, to
> inherit the home interface... considering the fact, that the ParentHome will
> have a
> public Parent findByPrimaryKey() while the child will need to have a
> public Child findByPrimaryKey() ... this is neither overriding nor
> overloading... and hence will give a compilation error. A no argument
> create() will also give rise to the same problem. So I gather that the
> child can inherit the remote interface but not the home interface.
> So, Parent's home is something like this
> public interface ParentHome extends javx.ejb.EJBHome{
> public Parent findByPrimaryKey() ;
> public Parent create();
> }
>
> and the Child's home would be
> public interface ChildHome extends javx.ejb.EJBHome{
> public Child findByPrimaryKey() ;
> public Child create();
> }
>
> Now, what happens in the BeanClass... I derive the ChildBean from the
> ParentBean
> public class ParntBean implements javax.ejb.EntityBean{
> public ParentPK ejbCreate(){
> // return ParentPk
> }
> public ParentPK ejbFindByPrimaryKey(){
> // return ParentPk
> }
>
> }
>
> public class ChildBean extends ParentBean{
> public ChildPK ejbCreate(){
> // return ChildPk
> }
> public ChildPK ejbFindByPrimaryKey(){
> // return ChildtPk
> }
> }
> The compilation of ChildBean class will give errors. I may be able to bypass
> this by declaring the ParentPK as the return type but in this case ejbc
> will give errors......
>
> Is this a restriction with Entity beans.. or is there some way to achieve
> inheritance.
> Any inputs will be most helpful.
>
> And also should the ChildPk be derived from ParentPK as in
> public class ChildPK extends ParentPK{
> int childId;
> }
>
> Thanks and Regards,
> Shelly
>
> About Inheritance in EJBs. I am presenting my views and doub
>
> ===========================================================================
> 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".
--
Jonathan Baker
Senior Architect
Internet Applications Division
Sybase, Inc.
[EMAIL PROTECTED]
+1 510 922-0460
===========================================================================
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".