Java Reference
In-Depth Information
As with session beans, you can also define quite a bit about how the container should manage
the entity bean in the application. This information is placed in the section that defines
application-assembly information. Here you can define transactional attributes, set up client
roles, and assign permissions to bean methods, among other things.
Client View of an Entity Bean
The client of an entity bean is similar to the client to a session bean. The same statement can
be used to look up the home interface for the entity bean that you would like to use.
12
After you have the home interface, major differences appear to the client. There are more ways
to obtain remote interfaces for an entity bean. Not only are there creation methods that enable
you to create a new entity bean, there are finder methods that allow you to look up existing
information from the persistent storage.
Creation is an acceptable option for any entity bean that is not defined as read-only.
Searching by use of finder methods is always an option. Every entity bean defines a
findByPrimaryKey() method that enables the client to find a specific bean instance by its
unique identifier. Other finder methods can also be defined that search based on other criteria.
With the creation methods, the remote interface for the new bean instance is returned from the
method. Remember that finder methods can be defined to return either a single remote inter-
face or a collection of remote interfaces.
The following code snippet gives an example of finding an entity bean:
Context initialContext = getInitialContext();
QuoteHome quoteHome =
(QuoteHome)javax.rmi.PortableRemoteObject.narrow(
initialContext.lookup(“Quote”), QuoteHome.class);
Quote = quoteHome.findByPrimaryKey(new QuotePk(1));
After the client has hold of a remote interface for an entity bean, it is business as usual. At this
point the client can invoke methods that access the entity bean's business logic. In many cases,
these method calls represent database updates.
Entity Bean Life Cycle
The life cycle for an entity bean instance is unique. Like session beans, it is driven by both
client activity and actions performed by the application server. An entity bean instance can
exist in three states.
The first state is the does not exist state. This is the state before the application server has
started. When the application server starts it will create a pool of entity beans. The number of
pooled beans is configurable during deployment. The bean instance will sit in the pooled state
until it is needed.
 
Search WWH ::




Custom Search