| 16 |
Q |
Why Use EJB? |
| |
A |
EJB helps in building enterprise
applications easily. Developers of EJB
needs to focus on business logic only.
All other features like transaction,
persistence etc will be managed by the
container. EJB provides developers
architectural independence |
| |
|
|
| 17 |
Q |
What are
the different methods of Entity Bean? |
| |
A |
An entity bean consists of 4 type of
methods: create methods, finder methods,
remove methods and home methods |
| |
|
|
| 18 |
Q |
What are create
methods of Entity Bean? |
| |
A |
Create methods are used to create a
new instance of a CMP entity bean. The
create() method on bean's home interface
returns an object of remote.
ejbCreate(parameters) methods are used
for creating Entity Bean instances
according to the parameters specified
and to some programmer-defined
conditions. We can declare more than one
create() methods in home interface, and
each of which must have a corresponding
ejbCreate() and ejbPostCreate() methods
in the bean class. These creation
methods are linked at run time, so that
when a create() method is invoked on the
home interface, the container delegates
the invocation to the corresponding
ejbCreate() and ejbPostCreate() methods
on the bean class. |
| |
|
|
| 19 |
Q |
What are finder
methods of Entity Bean? |
| |
A |
Finder methods are used to query for
specific entity beans. These are methods
declared in home interface and begin
with find. There are two kinds of finder
methods, single-entity and multi-entity.
Single-entity finder methods return a
remote object that matches given find
request. If no records found, this
method throws an ObjectNotFoundException
. The multi-entity finder methods return
a collection ( Enumeration or Collection
type) of entities that match the find
request. If no entities are found,
finder returns an empty collection. |
| |
|
|
| 20 |
Q |
What are remove
methods of Entity Bean ? |
| |
A |
Remove methods allow the client to
remove an Entity bean by specifying
either Handle or a Primary Key of that
Entity Bean. |
| |
|
|
| 21 |
Q |
What are home
methods in Entity Bean? |
| |
A |
Home methods are methods that are
designed and implemented by a developer
according to his/her needs. EJB
specification doesn't have any
requirements for home methods except
they need to throw a RemoteException. |
| |
|
|
| 22 |
Q |
What are
different callback methods in Entity
beans? |
| |
A |
The bean class implements a set of
callback methods that allow the
container to notify the events in its
life cycle. The call back methods
available in Entity Bean are
public void setEntityContext();
public void unsetEntityContext();
public void ejbLoad();
public void ejbStore();
public void ejbActivate();
public void ejbPassivate();
public void ejbRemove(); |
| |
|
|
| 23 |
Q |
What is the use
of setEntityContext in Entity bean? |
| |
A |
The setEntityContext() method
is used to set the EntityContext
interface for that bean.
The EntityContext contains
information about
the context under which bean is
operating. EntityContext interface gives security information about
caller. The EntityContext is
set only once in the life time of an
entity bean instance |
| |
|
|
| 24 |
Q |
What is the use
of unsetEntityContext in Entity Bean? |
| |
A |
The unsetEntityContext() method is
called at the end of a bean's life cycle
before the instance is unloaded from
memory. It is used to dereference
EntityContext and to perform any clean
up operations if required. |
| |
|
|
| 25 |
Q |
What are ejbLoad
and ejbStore methods of Entity Bean? |
| |
A |
ejbLoad method is primarily used for
data retrievals. ejbStore is used for
updating data. Typically the container
invokes ejbLoad before the first
business method in a transaction and the
ejbStore is invoked at the end of the
transaction. ejbStore method will be
invoked when we change some values in
memory. |
| |
|
|
| 26 |
Q |
What are ejbActivate and ejbPassivate
methods of Entity Bean? |
| |
A |
The ejbPassivate() is invoked by the
container before the beans is passivated
and ejbActivate() is invoked by the
container after the bean is activated.
Passivation and activation is used to
save resources. passivation means,
dissociating a bean instance from its
EJB object. Activation is the process of
associating a bean with EJB object.
Stateless session beans are never
passivated. |
| |
|
|
| 27 |
Q |
What is the
architecture of EJB? |
| |
A |
Every EJB is having three classes. A
home interface which acts as a factory
of remote objects. A remote object which
is used for client interaction and a
bean object which contains all the
business logic. |
| |
|
|
| 28 |
Q |
Can an Entity
bean have zero create methods? |
| |
A |
An entity bean ca have zero or more
create methods. If there is no create
methods we will not be able insert data
to the database. So that |
| |
|
|
| 29 |
Q |
What is the
default transaction attribute in EJB? |
| |
A |
The default transaction attribute is
'supports' |
| |
|
|
| 30 |
Q |
What are the
different transaction attributes ? |
| |
A |
There are six different transaction
attributes available: Not Supported,
Required, Supports, RequiresNew,
Mandatory, Never. |