This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes question about the way entity bean works? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "question about the way entity bean works?" Watch "question about the way entity bean works?" New topic
Author

question about the way entity bean works?

Robert Strong
Ranch Hand

Joined: Sep 10, 2002
Posts: 84
I'm wondering about the way entity bean works in BEA Weblogic8.1? I'm not sure whether my descriptions about entity bean below are correct or not?

when call Home.create() method
1 ejb container grab an instance from pool
2 ejb container call ejbCreate() method
3 ejb container insert record into the table in database
4 return primary key to ejb container
5 ejb container create an EJBObject for this primary key
6 ejb container return the remote reference to client

when call home.finderbyXXX() method
1 ejb container grab an instance from pool
2 ejb container call ejbfindXXX() method to return a list of primary keys to container
3 ejb container create a corresponding EJBObject for each primary key
4 ejb container return a list of remote references to client


when call a business method on remote reference

1 EJBObject would grab an instance from pool
2 ejb container load instance state from database using primary key from entitycontext
3 ejb container call business method on this instance.

how is the primary key stored in ejb container and how is it associated with EJBObject or Remote Reference? how is Remote reference associated with EJBObject?


any help appreciated!!
Edward Kenworthy
Ranch Hand

Joined: Oct 05, 2003
Posts: 66
The primary key is not stored in the container at all, it's stored in the database and in the entity itself (ie its one of its fields).
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
Hi,

Here is: the way I understood it.


1. The client performs lookup thru some jndi service. say IntialContext.lookup("SomeRemoteInterface") to get reference to RemoteHome interface.

2. Using narrow() we get a stub which implements the RemoteHome interface specified in narrow() parameter. This RemoteHome interface defines life-cycle methods (create,remove,find).

3. Using create method on the stub returned above, we pass on the request to invoke create method on actual bean on remote server. This stub uses sockets or some other way of connecting with server.

4. On server, an EJBObject ( an interface which is implemented by container. Its methods are getEJBHome(), getHandle(), getPrimaryKey(), isIdentical(EJBObject obj), remove() )is created.

5. This EJBObject is assigned an instance of a Bean from the pool. This instance is also assigned javax.ejb.EJBContext by the container which provides the instance with information about its client, EJBHome, EJBObject( which is used by instance to provide its reference to other beans, to create , locate or remove beans of its own types.). This Bean instance which doesn't implement any remote or local interface but implements entity or session beans and extends original bean class, has all the business methods( as those in remote interface),life cycle methods( as those in Home interface),and callback methods.

6. The original call to invoke create method in step 3 is first invoked on stub then on server-EJBObject which has the instance of bean with same create method, invokes the same method call on its instance bean. Now this instance's create method returns PrimaryKey( A class that implements Serializable interface).

7. The client never interacts directly with this bean instance, but do so thru stub in step3. The client has reference to EJBObject created in step5.

Note : The life cycle methods create,remove,find exists in RemoteHome interface,stub and original Bean but their implementation is different in stub and Bean class. The stub implementation provide a way of network communication between client and remote server where the bean resides using sockets or may be HttpConnection classes( I don't have much knowledge about them.). The Bean class implementation provides for sql for creating record in database.

Using same procedure thru stub the other methods like find or business methods are invoked on original bean instance.

When the client is no longer using bean then the EJBObject just has no reference to bean instance. The same EJBObject can refer to diff. bean instances at diff. time.

If someone else has different or further explanation for the above procedure please specify that.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: question about the way entity bean works?
 
Similar Threads
HFEJB p.96: How does EJB Lifecycle depend on different bean types?
question #8 p293
EJBObject management
Entity Bean -- Few Questions
Doubt on EJBObject