I am new to EJBs and I have some baisc questions :
1. I understand EJB uses some of RMI concepts. then why is that in RMI we write only one interface and in EJB we have two?
2. Who is responsible for creating the EJB object? The home interface or the container??
can you explain the basic functionality flow of EJBs
3. when the Home object gets a reference to the EJB object where is its refernce stored is it in the heap?? If so why???
The questions to anser is quite easy, but I'd suggest you really read something more about EJB:
1.) The Remote interface is equivalent (it is not the same, because it is not implemented by the bean) to your RMI interface, but the Home interface acts as a factory and is thus a different object seen from the client (an object-factory for the remote-objects).
2.) The container creates the EJB object; You create three interfaces/classes, "R" (remote), "H" (home) and "B" (bean), where B contains the functionalitiy that would be necessary to implement R and H.
The container now generates "intermediary" classes, it is up to the container how it does this but most do something like create a remote object which implements home interface and one which implements the remote interface. Some methods implemented in this interface simply delegate to the bean's implementation, so the "diagram" would look like:
where --> means implements/inherits and ->- means "method call"; RO=RemoteObject, HO=HomeObject, both container generated.
Comment: For entity bean CMP it is no different: the container generates "mediator" classes, "container"-classes, and is thus called "container" :-)
3.) The home-object actually is implemented by the container, and thus you have no possibility to "implement" it much. The idea is using the home as factory for the bean, and you provide necessary implementations all in one class, the bean class. Thus you cannot keep a reference to the bean in the home object, because you do not implement it. However, if the container would do this the reference would be on the heap. In the end it is all plain Java again (that is why some things are so clumsy).
Hope this helps a bit
1.RMI is one of the many concepts used by EJB like JNDI.
The remote interface serve the same purpose as in RMI. ie.. to make the ejb object network aware object.
The additional home interface ( using JNDI you get the home object) is written basically to have a pool of ejb objects
for obtaining scalablity of container.
2. the Ejb object is created by the home object, but in the container. we never write the code for ejb object. container generates automatically.
3. Not sure. i think it is propreitory logic of the ejb container.
RMI is the network application level protocol used to communicate over TCP/IP/Sockets network in case of EJB's for remote procedure call or invocatoion.
u never write a class who is going implments home and remote interface container will automatically writes these classes for u called support classes genrated by the container.in session bean with the home interface u will create the the sessiob object and for the entity bean new row in database is created /inserted.