• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

question about the way entity bean works?

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic