-
Inheritance in EJB (7 messages)
- Posted by: Huduguru Hudiguru
- Posted on: July 20 2000 10:19 EDT
How do I go about designing a EJB with inheritance ?Threaded Messages (7)
- Inheritance in EJB by Mehrdad Loghmani on July 20 2000 14:27 EDT
- Inheritance in EJB by Brian Matalus on July 20 2000 16:21 EDT
-
Inheritance in EJB by David Kempster on July 20 2000 05:39 EDT
- Inheritance in EJB by Adi Lev on July 23 2000 05:07 EDT
-
Inheritance in EJB by David Kempster on July 20 2000 05:39 EDT
- Inheritance in EJB by John Kuriakose on July 29 2000 15:51 EDT
- Inheritance in EJB by eddie chui on July 30 2000 10:57 EDT
- Inheritance in EJB by Brian Matalus on July 20 2000 16:21 EDT
- Inheritance in EJB by Thibault Cuvillier on July 20 2000 19:23 EDT
-
Inheritance in EJB[ Go to top ]
- Posted by: Mehrdad Loghmani
- Posted on: July 20 2000 14:27 EDT
- in response to Huduguru Hudiguru
It is easy to have it! your EJB class can extends the parent class, it is even recommended to put your model and accessor methods in the parent class and inherit it in the EJB. however for the parent methods to be accessable by the remote party you should have them in the remote interface.
Also note that the parent class method should throw the java.rmi.RemoteException and it should implements the serialize interface. -
Inheritance in EJB[ Go to top ]
- Posted by: Brian Matalus
- Posted on: July 20 2000 16:21 EDT
- in response to Mehrdad Loghmani
Yes. Base classes for EJB can be very handy. It works just the way that you would imagine it would... Very nice for common functionality... validation... etc.
public class MyFirstBean implements SessionBean
{
}
public class MySecondBean extends MyFirstBean
{
}
Additionally, the EJBRemote can also be extended so that you can define methods that all EJB implementations in a given project/package must support.
Thoughts?
[email protected] -
Inheritance in EJB[ Go to top ]
- Posted by: David Kempster
- Posted on: July 20 2000 17:39 EDT
- in response to Brian Matalus
Depends on what sort of EJB. Inheritance where you would most like to use it - Entity Beans - is a problem. In weblogic you can do it but only if they have exactly the same primary key. You cannot even have the one primary key inheret from the other primary key. -
Inheritance in EJB[ Go to top ]
- Posted by: Adi Lev
- Posted on: July 23 2000 05:07 EDT
- in response to David Kempster
For ejbLoad ejbStore ejbActivate etc. you can inherent
from a base EJB class. public method and member of Remote
interface can be implements also. You extends the Remote
interface itself.
Only ejbCreate ejbPostCreate and specifind ejbFind are to implemented on actual usually non inherent classes.
-
Inheritance in EJB[ Go to top ]
- Posted by: John Kuriakose
- Posted on: July 29 2000 15:51 EDT
- in response to Mehrdad Loghmani
I'd like to share my experience in developing a Web application that uses inheritance in entity and Session beans.
Thibault has highlighted the options very clear. Point 2 is what is EJB component inheritance and Point 3 is class inheritance.
In EJB Component Inheritance the EJB Bean class extends from the parent Bean class,
the EJB Remote Interface extends the parent Remote Interface
The Homes have no relationship.
For Entity beans - in a hierarchy ther are other challenges involved in O-R mapping.All Entity beans in a hierarchy share the primary key class of the parent EJB. This makes sense as you never want to alter the identity of the Entity
while extending the parent.
You may use Single Table mapping for an entire hierarchy of entity beans.
OR
use a Root-Leaf Mapping by mapping the parent(Root) to one Table and a separate Table for each sub-Bean in the Hierarchy.
Session Bean Component Hierarchies are very useful and almost indispensable in production systems - to provide the benefit of common behaviour.
My components have been deployed into IBM Webpshere and work very well. -
Inheritance in EJB[ Go to top ]
- Posted by: eddie chui
- Posted on: July 30 2000 22:57 EDT
- in response to John Kuriakose
Dear Sir,
I think your message is very clear and helpful. Do u receommend any web site which contains some examples ?
thanks,
Eddie -
Inheritance in EJB[ Go to top ]
- Posted by: Thibault Cuvillier
- Posted on: July 20 2000 19:23 EDT
- in response to Huduguru Hudiguru
There is 3 types of inheritance with EJB:
1-Remote interface inheritance
Inheritance create a strong dependency and rigidity in the design. It must be used very carrefully, because remote interfaces need stability. Another solution is to use interface aggregation.
You must be aware about remote interface cast-up or down with narrow: the results may be very differents of cast-up or down a local class and you will probably face some strange ClassCast.
2- EJB Implementation inherite from another EJB implementation
You can face some strange behaviors such as:
- The search methods does not search for the subclasses
- The primary keys do not support inheritance
The semantic of "EJB inheritance" does not match exactly the OO semantic.
3- EJB Implementation inherite from a non distributed class
This is probably the more frequent usage of inheritance. The base class contains re-usabel code for the layer of the application.
i.e, in the Business layer containing your application business objects, you can create an AbstractBusinessObject class and extends all the EJB of this layer from this common super class.
So, I use the following rules:
- Avoid sub-classing the remote interface, use interface aggregation,
- Do not sub class an EJB from another one
- Always use implementation inheritance to share re-usable code for each layer of the architecture.
Remark, I don't have a large experience of EJB inheritance... so "handle this comments with care!".