SOLUTIONS/ANSWERS
1) Enterprise JavaBeans extends the JavaBeans component model to handle the needs
of transactional business applications.
of transactional business applications.
JavaBeans is a component model for the visual construction of reusable components
for the Java platform. Enterprise JavaBeans extends JavaBeans to middle-tier/server
side business applications. The extensions that Enterprise JavaBeans adds to
JavaBeans include support for transactions, state management, and deployment time
attributes.
for the Java platform. Enterprise JavaBeans extends JavaBeans to middle-tier/server
side business applications. The extensions that Enterprise JavaBeans adds to
JavaBeans include support for transactions, state management, and deployment time
attributes.
Although applications deploying Enterprise JavaBeans architecture are independent
of the underlying communication protocol, the architechture of the Enterprise
JavaBeans specifies how communication among components, maps into the underlying communication protocols, such as CORBA/IIOP.
of the underlying communication protocol, the architechture of the Enterprise
JavaBeans specifies how communication among components, maps into the underlying communication protocols, such as CORBA/IIOP.
2) Different types of Enterprise Beans are following :
• Stateless Session Bean: An instance of these non-persistent EJBs provides
service without storing an interaction or conversation state between methods.
Any instance can be used for any client.
• Stateful Session Bean: An instance of these non-persistent EJBs maintains
state across methods and transactions. Each instance is associated with a
particular client.\
• Entity Bean: An instance of these persistent EJBs represents an object view of
the data, usually rows in a database. They have a primary key as a unique
identifier. Entity bean persistence can be either container-managed or beanmanaged.
• Message:Driven Bean: An instance of these EJBs is integrated with the Java
Message Service (JMS) to provide the ability for message-driven beans to act as
a standard JMS message consumer and perform asynchronous processing
between the server and the JMS message producer.
service without storing an interaction or conversation state between methods.
Any instance can be used for any client.
• Stateful Session Bean: An instance of these non-persistent EJBs maintains
state across methods and transactions. Each instance is associated with a
particular client.\
• Entity Bean: An instance of these persistent EJBs represents an object view of
the data, usually rows in a database. They have a primary key as a unique
identifier. Entity bean persistence can be either container-managed or beanmanaged.
• Message:Driven Bean: An instance of these EJBs is integrated with the Java
Message Service (JMS) to provide the ability for message-driven beans to act as
a standard JMS message consumer and perform asynchronous processing
between the server and the JMS message producer.
3) Java Bean is a plain java class with member variables and getter setter methods.
Java Beans are defined under JavaBeans specification as Java-Based software
component model which includes features such as introspection, customisation,
events, properties and persistence.
Java Beans are defined under JavaBeans specification as Java-Based software
component model which includes features such as introspection, customisation,
events, properties and persistence.
Enterprise JavaBeans or EJBs for short are Java-based software components that
comply with Java’s EJB specification. EJBs are delpoyed on the EJB container and
execute in the EJB container. EJB is not that simple, it is used for building
distributed applications.
comply with Java’s EJB specification. EJBs are delpoyed on the EJB container and
execute in the EJB container. EJB is not that simple, it is used for building
distributed applications.
Examples of EJB are Session Bean, Entity Bean and Message Driven Bean. EJB is
used for server side programming whereas java bean is a client side programme.
While Java Beans are meant only for development the EJB is developed and then
deployed on EJB Container.
used for server side programming whereas java bean is a client side programme.
While Java Beans are meant only for development the EJB is developed and then
deployed on EJB Container.
4) Entity Beans can have no create() methods. Entity Beans have no create() an
method, when an entity bean is not used to store the data in the database. In this
case, entity bean is used to retrieve the data from the database.
method, when an entity bean is not used to store the data in the database. In this
case, entity bean is used to retrieve the data from the database.
5) Callback methods are called for, by the container to notify the important events to
the beans in its life cycle. The callback methods are defined in the
javax.ejb.EntityBean interface.The callback methods example are ejbCreate(),
ejbPassivate(), and ejbActivate().
the beans in its life cycle. The callback methods are defined in the
javax.ejb.EntityBean interface.The callback methods example are ejbCreate(),
ejbPassivate(), and ejbActivate().
6) An entity bean consists of 4 groups of methods:
• Create methods: To create a new instance of a CMP entity bean, and therefore,
insert data into the database, the create() method on the bean's home interface
must be invoked. They look like this: EntityBeanClass
ejbCreateXXX(parameters), where EntityBeanClass is an Entity Bean you are
trying to instantiate, ejbCreateXXX(parameters) methods are used for creating
Entity Bean instances according to the parameters specified and to some
programmer-defined conditions.
insert data into the database, the create() method on the bean's home interface
must be invoked. They look like this: EntityBeanClass
ejbCreateXXX(parameters), where EntityBeanClass is an Entity Bean you are
trying to instantiate, ejbCreateXXX(parameters) methods are used for creating
Entity Bean instances according to the parameters specified and to some
programmer-defined conditions.
A bean’s home interface may declare zero or more create() methods, each of
which must have 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.
which must have 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.
3) Java Bean is a plain java class with member variables and getter setter methods.
Java Beans are defined under JavaBeans specification as Java-Based software
component model which includes features such as introspection, customisation,
events, properties and persistence.
Java Beans are defined under JavaBeans specification as Java-Based software
component model which includes features such as introspection, customisation,
events, properties and persistence.
Enterprise JavaBeans or EJBs for short are Java-based software components that
comply with Java’s EJB specification. EJBs are delpoyed on the EJB container and
execute in the EJB container. EJB is not that simple, it is used for building
distributed applications.
comply with Java’s EJB specification. EJBs are delpoyed on the EJB container and
execute in the EJB container. EJB is not that simple, it is used for building
distributed applications.
Examples of EJB are Session Bean, Entity Bean and Message Driven Bean. EJB is
used for server side programming whereas java bean is a client side programme.
While Java Beans are meant only for development the EJB is developed and then
deployed on EJB Container.
used for server side programming whereas java bean is a client side programme.
While Java Beans are meant only for development the EJB is developed and then
deployed on EJB Container.
4) Entity Beans can have no create() methods. Entity Beans have no create() an
method, when an entity bean is not used to store the data in the database. In this
case, entity bean is used to retrieve the data from the database.
5) Callback methods are called for, by the container to notify the important events to
the beans in its life cycle. The callback methods are defined in the
javax.ejb.EntityBean interface.The callback methods example are ejbCreate(),
ejbPassivate(), and ejbActivate().
method, when an entity bean is not used to store the data in the database. In this
case, entity bean is used to retrieve the data from the database.
5) Callback methods are called for, by the container to notify the important events to
the beans in its life cycle. The callback methods are defined in the
javax.ejb.EntityBean interface.The callback methods example are ejbCreate(),
ejbPassivate(), and ejbActivate().
6) An entity bean consists of 4 groups of methods:
• Create methods: To create a new instance of a CMP entity bean, and therefore,
insert data into the database, the create() method on the bean's home interface
must be invoked. They look like this: EntityBeanClass
ejbCreateXXX(parameters), where EntityBeanClass is an Entity Bean you are
trying to instantiate, ejbCreateXXX(parameters) methods are used for creating
Entity Bean instances according to the parameters specified and to some
programmer-defined conditions.
insert data into the database, the create() method on the bean's home interface
must be invoked. They look like this: EntityBeanClass
ejbCreateXXX(parameters), where EntityBeanClass is an Entity Bean you are
trying to instantiate, ejbCreateXXX(parameters) methods are used for creating
Entity Bean instances according to the parameters specified and to some
programmer-defined conditions.
A bean’s home interface may declare zero or more create() methods, each of
which must have 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.
which must have 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.
• Finder methods: The methods in the home interface that begin with “find” are
called the find methods. These are used to query to the EJB server for specific
entity beans, based on the name of the method and arguments passed.
Unfortunately, there is no standard query language defined for find methods, so
each vendor will implement the find method differently. In CMP entity beans,
the find methods are not implemented with matching methods in the bean class;
containers implement them when the bean is deployed in a vendor specific
manner. The deployer will use vendor specific tools to tell the container how a
particular find method should behave. Some vendors will use object-relational
mapping tools to define the behaviour of a find method while others will simply
require the deployer to enter the appropriate SQL command.
called the find methods. These are used to query to the EJB server for specific
entity beans, based on the name of the method and arguments passed.
Unfortunately, there is no standard query language defined for find methods, so
each vendor will implement the find method differently. In CMP entity beans,
the find methods are not implemented with matching methods in the bean class;
containers implement them when the bean is deployed in a vendor specific
manner. The deployer will use vendor specific tools to tell the container how a
particular find method should behave. Some vendors will use object-relational
mapping tools to define the behaviour of a find method while others will simply
require the deployer to enter the appropriate SQL command.
There are two basic kinds of find methods: single-entity and multi-entity.
Single-entity find methods return a remote reference to the one specific entity
bean that matches the find request. If, no entity beans are found, the method
throws an ObjectNotFoundException . Every entity bean must define the
Single-entity find methods return a remote reference to the one specific entity
bean that matches the find request. If, no entity beans are found, the method
throws an ObjectNotFoundException . Every entity bean must define the
single-entity find method with the method name findByPrimaryKey(), which
takes the bean's primary key type as an argument.
takes the bean's primary key type as an argument.
The multi-entity find methods return a collection ( Enumeration or Collection
type) of entities that match the find request. If, no entities are found, the multientity
find returns an empty collection.
type) of entities that match the find request. If, no entities are found, the multientity
find returns an empty collection.
• Remove methods: These methods (you may have up to 2 remove methods, or
don't have them at all) allow the client to physically remove Entity beans by
specifying either Handle or a Primary Key for the Entity Bean.
don't have them at all) allow the client to physically remove Entity beans by
specifying either Handle or a Primary Key for the Entity Bean.
• Home methods: These methods are designed and implemented by a developer,
and EJB specifications do not require them as such, except when, there is the
need to throw a RemoteException in each home method.
and EJB specifications do not require them as such, except when, there is the
need to throw a RemoteException in each home method.
7) Asynchronous notification is a known hole in the first versions of the EJB spec. The
recommended solution to this is to use JMS (Java Messaging Services), which is
now, available in J2EE-compliant servers. The other option, of course, is to use
client-side threads and polling. This is not an ideal solution, but it’s workable for
many scenarios
recommended solution to this is to use JMS (Java Messaging Services), which is
now, available in J2EE-compliant servers. The other option, of course, is to use
client-side threads and polling. This is not an ideal solution, but it’s workable for
many scenarios
8) Entity Beans actually represents the data in a database. It is not that Entity Beans
replaces JDBC API. There are two types of Entity Beans - Container Managed
and Bean Mananged. In a Container Managed Entity Bean – Whenever, the
instance of the bean is created, the container automatically retrieves the data from
the DB/Persistance storage and assigns to the object variables in the bean for the
user to manipulate or use them. For this, the developer needs to map the fields in
the database to the variables in deployment descriptor files (which varies for each
vendor). In the Bean Managed Entity Bean - the developer has to specifically make
connection, retrive values, assign them to the objects in the ejbLoad() which will be
called for, by the container when it instatiates a bean object. Similarly, in the
ejbStore() the container saves the object values back to the persistance storage.
ejbLoad and ejbStore are callback methods and can only be invoked by the
container. Apart from this, when you are use Entity beans you do not need to worry
about database transaction handling, database connection pooling etc. which are
taken care of by the ejb container. But, in case of JDBC you have to explicitly take
care of the above features. The great thing about the entity beans is that container
managed is, that, whenever the connection fail during transaction processing, the
database consistancy is mantained automatically. The container writes the data
stored at persistant storage of the entity beans to the database again to provide the
database consistancy. Whereas in jdbc api, developers need to maintain the
consistency of the database manually.
replaces JDBC API. There are two types of Entity Beans - Container Managed
and Bean Mananged. In a Container Managed Entity Bean – Whenever, the
instance of the bean is created, the container automatically retrieves the data from
the DB/Persistance storage and assigns to the object variables in the bean for the
user to manipulate or use them. For this, the developer needs to map the fields in
the database to the variables in deployment descriptor files (which varies for each
vendor). In the Bean Managed Entity Bean - the developer has to specifically make
connection, retrive values, assign them to the objects in the ejbLoad() which will be
called for, by the container when it instatiates a bean object. Similarly, in the
ejbStore() the container saves the object values back to the persistance storage.
ejbLoad and ejbStore are callback methods and can only be invoked by the
container. Apart from this, when you are use Entity beans you do not need to worry
about database transaction handling, database connection pooling etc. which are
taken care of by the ejb container. But, in case of JDBC you have to explicitly take
care of the above features. The great thing about the entity beans is that container
managed is, that, whenever the connection fail during transaction processing, the
database consistancy is mantained automatically. The container writes the data
stored at persistant storage of the entity beans to the database again to provide the
database consistancy. Whereas in jdbc api, developers need to maintain the
consistency of the database manually.
9) The bean class defines create methods that match methods in the home interface
and business methods that match methods in the remote interface. The bean class
also implements a set of callback methods that allow the container to notify the
bean of events in its life cycle. The callback methods are defined in the
javax.ejb.EntityBean interface that is implemented by all entity beans.The
EntityBean interface has the following definition. Notice that, the bean class
implements these methods.
and business methods that match methods in the remote interface. The bean class
also implements a set of callback methods that allow the container to notify the
bean of events in its life cycle. The callback methods are defined in the
javax.ejb.EntityBean interface that is implemented by all entity beans.The
EntityBean interface has the following definition. Notice that, the bean class
implements these methods.
public interface javax.ejb.EntityBean {
public void setEntityContext();
public void unsetEntityContext();
public void ejbLoad();
public void ejbStore();
public void ejbActivate();
public void ejbPassivate();
public void setEntityContext();
public void unsetEntityContext();
public void ejbLoad();
public void ejbStore();
public void ejbActivate();
public void ejbPassivate();
public void ejbRemove();
}
The setEntityContext() method provides the bean with an interface to the container
called the EntityContext. The EntityContext interface contains methods for
obtaining information about the context under which the bean is operating at any
particular moment. The EntityContext interface is used to access security
information about the caller; to determine the status of the current transaction or to
force a transaction rollback; or to get a reference to the bean itself, its home, or its
primary key. The EntityContext is set only once in the life of an entity bean
instance, so its reference should be put into one of the bean instance’s fields if it
will be needed later.
}
The setEntityContext() method provides the bean with an interface to the container
called the EntityContext. The EntityContext interface contains methods for
obtaining information about the context under which the bean is operating at any
particular moment. The EntityContext interface is used to access security
information about the caller; to determine the status of the current transaction or to
force a transaction rollback; or to get a reference to the bean itself, its home, or its
primary key. The EntityContext is set only once in the life of an entity bean
instance, so its reference should be put into one of the bean instance’s fields if it
will be needed later.
The unsetEntityContext() method is used at the end of the bean’s life cycle before
the instance is evicted from the memory to dereference the EntityContext and
perform any last-minute clean-up.
the instance is evicted from the memory to dereference the EntityContext and
perform any last-minute clean-up.
The ejbLoad() and ejbStore() methods in CMP entities are invoked when the entity
bean's state is being synchronised with the database. The ejbLoad() is invoked just
after the container has refreshed the bean container-managed fields with its state
from the database.
bean's state is being synchronised with the database. The ejbLoad() is invoked just
after the container has refreshed the bean container-managed fields with its state
from the database.
The ejbStore() method is invoked just before the container is about to write the bean
container-managed fields to the database. These methods are used to modify data as
it is being synchronised. This is common when the data stored in the database is
different than the data used in the bean fields.
container-managed fields to the database. These methods are used to modify data as
it is being synchronised. This is common when the data stored in the database is
different than the data used in the bean fields.
The ejbPassivate() and ejbActivate() methods are invoked on the bean by the
container just before the bean is passivated and just after the bean is activated,
respectively. Passivation in entity beans means that the bean instance is
disassociated with its remote reference so that the container can evict it from the
memory or reuse it. It’s a resource conservation measure that the container employs
to reduce the number of instances in the memory. A bean might be passivated if it
hasn’t been used for a while or as a normal operation performed by the container to
maximise reuse of resources. Some containers will evict beans from the memory,
while others will reuse instances for other more active remote references. The
ejbPassivate() and ejbActivate() methods provide the bean with a notification as to
when it's about to be passivated (disassociated with the remote reference) or
activated (associated with a remote reference).
container just before the bean is passivated and just after the bean is activated,
respectively. Passivation in entity beans means that the bean instance is
disassociated with its remote reference so that the container can evict it from the
memory or reuse it. It’s a resource conservation measure that the container employs
to reduce the number of instances in the memory. A bean might be passivated if it
hasn’t been used for a while or as a normal operation performed by the container to
maximise reuse of resources. Some containers will evict beans from the memory,
while others will reuse instances for other more active remote references. The
ejbPassivate() and ejbActivate() methods provide the bean with a notification as to
when it's about to be passivated (disassociated with the remote reference) or
activated (associated with a remote reference).
10) Session and Entity EJBs consist of 4 and 5 parts respectively
a) A remote interface (a client interacts with it),
b) A home interface (used for creating objects and for declaring business
methods),
c) A bean object (an object, which actually performs business logic and EJBspecific
operations).
d) A deployment descriptor (an XML file containing all information required for
maintaining the EJB) or a set of deployment descriptors (if you are using some
container-specific features).
e) A Primary Key class - that is only Entity bean specific.
b) A home interface (used for creating objects and for declaring business
methods),
c) A bean object (an object, which actually performs business logic and EJBspecific
operations).
d) A deployment descriptor (an XML file containing all information required for
maintaining the EJB) or a set of deployment descriptors (if you are using some
container-specific features).
e) A Primary Key class - that is only Entity bean specific.
11) A session bean is a non-persistent object that implements some business logic
running on the server. One way to think of a session object is as a logical extension
of the client program that runs on the server.
Session beans are used to manage the interactions of entity and other session beans,
access resources, and generally perform tasks on behalf of the client.
running on the server. One way to think of a session object is as a logical extension
of the client program that runs on the server.
Session beans are used to manage the interactions of entity and other session beans,
access resources, and generally perform tasks on behalf of the client.
There are two basic kinds of session bean: Stateless and Stateful.
Stateless session beans are made up of business methods that behave like
procedures; they operate only on the arguments passed to them when they are
invoked. Stateless beans are called stateless because they are transient; they do not
maintain business state between method invocations.Each invocation of a stateless
business method is independent of any previous invocations. Because stateless
session beans are stateless, they are easier for the EJB container to manage, so they
tend to process requests faster and use less resources.
procedures; they operate only on the arguments passed to them when they are
invoked. Stateless beans are called stateless because they are transient; they do not
maintain business state between method invocations.Each invocation of a stateless
business method is independent of any previous invocations. Because stateless
session beans are stateless, they are easier for the EJB container to manage, so they
tend to process requests faster and use less resources.
Stateful session beans encapsulate business logic and are state specific to a client.
Stateful beans are called “tateful” because they do maintain business state between
method invocations, held the in memory and not persistent. Unlike stateless session
beans, clients do not share stateful beans. When a client creates a stateful bean, that
bean instance is dedicated to the service of only that client. This makes it possible
to maintain conversational state, which is business state that can be shared by
methods in the same stateful bean.
Stateful beans are called “tateful” because they do maintain business state between
method invocations, held the in memory and not persistent. Unlike stateless session
beans, clients do not share stateful beans. When a client creates a stateful bean, that
bean instance is dedicated to the service of only that client. This makes it possible
to maintain conversational state, which is business state that can be shared by
methods in the same stateful bean.
No comments:
Post a Comment