ENTITY AND SESSION BEANS Flashcards
What is an entity?
A entity is a group of states associated
together in a single unit. On adding
behaviour, it behaves as an object and
becomes a major constituent of
object-oriented paradign. We can therefore
say that an entity is an application-defined
object in Java persistence library
What is a java bean
A java bean is a class that is serializable,
has a no-argument constructor and uses
getters and setter methods for its member
fields
Give characteristics of entity beans
Are persistent- its state exists beyond lifetime of application(It is relatively long lived)
Have primary keys: Unique identifier
It is recoverable- it survives failures of the EJB server
Is typically stateful
May be re-entrant
Allow shared access: Can be shared by multiple clients
Can have relationships with other entity beans
Give characteristics of session beans
They are not permanent in nature.(It is relatively short lived)
They implement conversational state between the client and the J2EE server.
They service a single client request at a time.
Has no primary key
May be stateful or stateless
It is not recoverable-if the EJB server fails,it may be destroyed
Is not re-entrant
They enable you to access data stored in a database
What are the different types of entity beans?
- Bean managed persistence
- Is a type of entity bean that gives the developer explicit control of the management of a bean instance’s state.
- In this entity, the programmer must write a code for database calls since the entity persists across multiple sessions and clients - Container managed persistence
- Is an entity bean that allows the developer to use the deployment descriptor to tell the container which attributes of the entity bean to persist.
- Container managed persistence are persistent across database and takes care of database calls
What are the entity beans constituents(classes and such)
Remote interface(EJBObject) Defines business methods of the bean
Home interface(Extends EJBHome) Defines methods that allow a client to create and find an entity bean
Enterprise bean class(Entity/Session bean) Provides implementation for the business methods,finder and home methods
Primary key class: makes it possible to identify entity bean uniquely
Deployment descriptor: (ejb-jar.xml) This configuration document defines the bean’s runtime attributes,such as its transactions or security attributes
Helper class: other classes needed by the enterprise bean class, such as exception and utility classes
Briefly describe session beans
Session beans are created by a customer and their duration is only for the single client server session
The function performed by this bean is calculations or database access, for the client.
Sessions further subdivide into two;
stateless and stateful session beans
Describe stateless session beans
A Stateless session bean doesn’t keep a conversational state with the customer or client
When a client invokes the methods for a stateless bean, the bean’s instance variable may contain a state explicitly to that client however only for the span of the invocation.
Describe stateful session beans
A stateful session bean is the same as an interactive session. The state of an object comprises the values of its instance variables. In a stateful session bean, the instance variables denote the state of a unique client/bean session.
Since, the client interacts with its bean. The state is usually called the conversational state. It maintains the state of a client across multiple requests. So, we cannot implement it in the web services because it cannot be shared. When the client terminates the session, it is no longer associated with the client
Describe message driven beans and give their characteristics
Message bean is similar to session bean, except it responds to java message service.
Characteristics
They execute upon receipt of a single client message.
They are invoked asynchronously.
They are relatively short-lived.
They do not represent directly shared data in the database, but
they can access and update this data.
They can be transaction-aware.
They are stateless.
What are the different types of Enterprise java bean. Give examples and importances of each
1.Session bean eg TimerSessionBean: a stateless session bean that sets a timer.
The session bean performs work for its client, shielding the client from complexity by executing business tasks inside the server.
2. Message Driven Bean eg classes created from the javax.ejb.MessageDriven;
Adv- Concurrent processing of streams of messages
-A single message-driven bean can process messages from multiple clients.
3. Entity Bean eg customers, orders, and products.
Adv- he advantage of Entity bean is that it can benefit from standardization and industry best practices, simplifying some of the complexity of enterprise development.
What are some of the features offered by EJB
Security Concurrency Networking Transaction management Resource management Persistence Messaging Customization
Enterprise Beans are an important aspect of OOP in the creation of a distributed system.
Using an elaborate diagram, describe the various components that form the ecosystem
of an Enterprise system.
SEE https://www.javastackflow.com/2014/08/introduction-to-ejb.html for pic
1 ) EJB Server :
It provides execution environment for server components.
It hosts EJB containers.
2) EJB Container:
It serves as interface EJB and Outside World.
Container hosts the EJB Object, Remote Interface, Home Object, Home Interface and the Local Interface
3) Enterprise Beans:
They are EJB Components that encapsulates business functionalities in an application.
Container provides security to enterprise beans.
4) EJB Client:
It makes use of EJB beans to perform the operations.
Client locates the container using JNDI (Java Naming & Directory Interface)
Then the client invokes JB Beans machines through container
5) Deployment Descriptor:
It lists the bean properties and elements like:
) Describe any three components that must go into the creation of an enterprise bean.
df