Search your topic in Java2share
Home > FAQs
eXTReMe Tracker


EJB FAQs


41).What is the difference between sessioncontext and entitycontext?

Since EnterpriseBeans live in a managed container,the container is free to call your EJB components methods at its leisure.

The container houses the information like current status of bean,security credentials of the user currently accessing the bean in one object is called EJBContext Object.

A context represents a way for beans to perform callbacks and modify their current status

SessionContext is EJB context for session bean

EntityContext is EJB context for entity bean

Message driven context is EJB context for message driven bean

42). What is the difference between ejbStore() and ejbLoad()?

ejbStore() will be called before ejbPassivate() and is used to store the object to persistent database.
ejbLoad() will be called before ejbActivate() and is used to retrieve the object from persistence datastore.

43). What is the difference between EAR, JAR and WAR file?
J2EE defines three types of archives:

1. Java Archives (JAR)—A JAR file encapsulates one or more Java

classes, a manifest, and a descriptor. JAR files are the lowest

level of archive. JAR files are used in J2EE for packaging EJBs

and client-side Java Applications.

2. Web Archives (WAR)—WAR files are similar to JAR files, except

that they are specifically for web applications made from

Servlets, JSPs, and supporting classes.

3. Enterprise Archives (EAR)—An EAR file contains all of the

components that make up a particular J2EE application.

44).How to implement an entity bean which the PrimaryKey is an autonumeric?

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, thebean 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 theentity 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.)

45). Is Decorator an EJB design pattern?

No. Decorator design pattern, is the one which exhibits very low level runtime polymorphism, for the specific and single object (Instance of the class), but not for atleast for a class. It is the stuff to add specific functionality to a single & pointed object and leaves others like it unmodified. It is having close similarities like aspect stuff, but not with EJB stuff.

46). What is lazy loading?
Lazy loading means not creating an object until the first time it is accessed. Lazy loading typically looks like this:

public class Example {
private Vector data = null;

public Vector getData() {
if (this.data == null) {
this.data = new Vector();
// Load data into vector ...
}
return this.data;
}
}

This technique is most useful when you have large hierarchies of objects (such as a product catalog). You can lazy-load subordinate objects as you navigate down the hierarchy, and thereby only creat objects when you need them.

47). What is Message Driven Bean?

An MDB is essentially a message consumer that can listen to a message destination or a message endpoint and gets activated when a message arrives. By design, MDBs are anonymous in nature and hence cannot be directly invoked by a client. The only way to invoke an MDB is to send a message to the destination or endpoint to which it is listening. As MDBs are stateless in nature and are not related to any specific client, they can be pooled for concurrent processing of messages.

48). What is CMR?

CMR is an acronym for Container Managed Relation-ships.
CMR, represented by the cmr fields in the deployment descriptor, which represents the relationship exists between different entities (entity beans), which are in turn exhibiting the database to the real world. The relationships are one-one, one-many, & many-many.
All the relations/ referential integrities will be managed by container, then the definition's in the deployment descriptor's are called as Container Managed Relationships (CMR)..

49). 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)

50). What are the optional clauses in EJB QL?

WHERE and ORDERBY clauses are optional in EJB QL where as SELECT and FROM are required clauses.