|
EJB Interview Questions and Answers
What is EJB QL?
EJB QL is a Query Language provided for navigation across a network of
enterprise beans and dependent objects defined by means of container managed
persistence. EJB QL is introduced in the EJB 2.0 specification. The EJB QL query
language defines finder methods for entity beans with container managed
persistenceand is portable across containers and persistence managers. EJB QL is
used for queries of two types of finder methods: Finder methods that are defined
in the home interface of an entity bean and which return entity objects. Select
methods, which are not exposed to the client, but which are used by the Bean
Provider to select persistent values that are maintained by the Persistence
Manager or to select entity objects that are related to the entity bean on which
the query is defined.
Can the primary key in
the entity bean be a Java primitive type such as int?
The primary key can’t be a primitive type–use the primitive wrapper classes,
instead. For example, you can use java.lang.Integer as the primary key
class, but not int (it has to be a class, not a primitive)
How EJB Invocation
happens?
Step 1: Retrieve Home Object reference from Naming Service via JNDI.
step 2: Return Home Object reference to the client.
step 3: Create me a new EJB Object through Home Object interface.
step 4: Create EJB Object from the Ejb Object
step 5: Return EJB Object reference to the client.
step 6: Invoke business method using EJB Object reference.
step 7: Delegate request to Bean (Enterprise Bean).
What are transaction
attributes?
The transaction attribute specifies how the Container must manage
transactions for a method when a client invokes the method via the
enterprise bean’s home or component interface or when the method is invoked
as the result of the arrival of a JMS message. (Sun’s EJB Specification)
Below is a list of transactional attributes:
1. NotSupported - transaction context is unspecified.
2. Required - bean’s method invocation is made within a transactional
context. If a client is not associated with a transaction, a new transaction
is invoked automatically.
3. Supports - if a transactional context exists, a Container acts like the
transaction attribute is Required, else - like NotSupported.
4. RequiresNew - a method is invoked in a new transaction context.
5. Mandatory - if a transactional context exists, a Container acts like the
transaction attribute is Required, else it throws a
javax.ejb.TransactionRequiredException.
6. Never - a method executes only if no transaction context is specified.
What is Session Bean?
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.
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 from 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 state specific to a
client. Stateful beans are called “stateful” because they do maintain
business state between method invocations, held 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 service 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.
What are the different
kinds of enterprise beans?
Stateless session bean- An instance of these non-persistent EJBs provides a
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
bean-managed.
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.
Page Numbers :
1
2
3
4
5
6
7
8
9
10
Have a Question ?
post your questions here. It
will be answered as soon as possible.
Check
Java Interview
Questions for more Java Interview Questions with answers
Check
Structs Interview
Questions for more Structs Interview Questions with answers
|