Search This Blog

Saturday, March 04, 2006

EJB Interview Questions Part-3

Does Stateful Session bean support instance pooling?
Stateful Session Bean conceptually doesn't have instance pooling.

Can I map more than one table in a CMP?
no, you cannot map more than one table to a single CMP Entity Bean. CMP has been, in fact, designed to map a single table.

Can I invoke Runtime.gc() in an EJB?
You shouldn't. What will happen depends on the implementation, but the call will most likely be ignored.

Can a Session Bean be defined without ejbCreate() method?
The ejbCreate() methods is part of the bean's lifecycle, so, the compiler will not return an error because there is no ejbCreate() method.

However, the J2EE spec is explicit:

• the home interface of a Stateless Session Bean must have a single create() method with no arguments,
while the session bean class must contain exactly one ejbCreate() method, also without arguments.

• Stateful Session Beans can have arguments (more than one create method)

How to implement an entity bean which the PrimaryKey is an autonumeric field
The EJB 2 Spec (10.8.3 - Special case: Unknown primary key class) says that in cases where the PrimaryKeys are generated automatically by the underlying database, the bean provider must declare the findByPrimaryKey method to return java.lang.Object and specify the Primary Key Class as java.lang.Object in the Deployment Descriptor.

When defining the Primary Key for the Enterprise Bean, the Deployer using the Container Provider's tools will typically add additional container-managed fields to the concrete subclass of the entity bean class.

In this case, the Container must generate the Primary Key value when the entity bean instance is created (and before ejbPostCreate is invoked on the instance.)

What is clustering?
Clustering is grouping machines together to transparantly provide enterprise services. Clustering is an essential piece to solving the needs for today's large websites.

The client does not know the difference between approaching one server or approaching a cluster of servers.


Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?


You can pass the HttpSession as parameter to an EJB method,only if all objects in session are serializable. This has to be consider as "passed-by-value", that means that it's read-only in the EJB. If anything is altered from inside the EJB, it won't be reflected back to the HttpSession of the Servlet Container.

If my session bean with single method insert record into 2 entity beans, how can know that the process is done in same transaction (the attributes for these beans are Required)?

No comments: