A primary key is a unique
identifier of a Java object that doesn’t necessarily have to relate directly
(or at all) to a primary key of a database table. It isn’t always necessary to
write a primary key class because it is possible to use Java objects defined in
the entity bean class such as Strings or Integers as primary keys. Primitive types such as int can be used only
if properly wrapped by Java objects.
A primary key class is defined
inside of the deployment descriptor.
Although an entity bean class can define a unique class as its primary
key, it is possible for multiple entity beans to use the same primary key
class. If two entity objects have the
same home instance and the same primary key, they are considered to be
identical.
This is where the bulk of the
business get/set logic goes.
The home interface should extend
the EJBLocalHome interface in cases where the client will be calling the entity
bean from inside the same EJB container, such as servlet-based database
applications. If the client will be
calling the entity bean from outside the EJB container, the home interface
should extend the EJBHome interface.
Methods of choice are exposed to
clients in either the local or remote interface. The local interface extends the EJBLocalObject interface, whereas
the remote interface extends the EJBObject interface.
The primary key class can be
extended from any base class. In order
to be a valid RMI/IIOP type, the primary key must implement the Serializable
interface. A hashCode() method and an
equals() method must be implemented in order for the EJB container to manage
primary keys. These methods are
necessary for the container to determine whether particular instances are the
same.
Benefits of using
container-managed persistence include:
Drawbacks to use of container-managed
persistence include:
A client application can be
either remote or local. A remote client
can be another bean either in the same or different EJB container, a Java
program, or a non-Java program. A local
client must run inside of the same JVM as the entity bean.
To create
a Web application that contains one or more JSP pages
+
document root directory – holds .jsp, .html, .js files
|
|-------
“WEB-INF” - holds web.xml, .tlds (taglib descriptors)
|
|---------
“classes” - holds servlet, bean, or tag
classes
(with subdirectories for packages)
|
|---------
“lib” - contains JARS of servlets, JavaBeans, and other
utility classes that are part of the
application.
|
|---------
any other directories you like (e.g. for images, etc.)
The life
cycle of Enterprise JavaBeans
Guideline: Use of stateful versus stateless session
beans
Stateful session beans should be considered when any of the
following conditions are true:
Stateless session beans may be considered when either of
the following conditions are true:
Personal
roles or EJB development
The J2EE standard describes roles for developers who must
perform the different types of tasks necessary to create and deploy a J2EE/EJB
application. Some of these roles are:
Deploying
the application
J2EE applications and components are packaged in a standard
way, defined by the J2EE specs. First, create the .war file (as described
above). Put all your EJBs inside a .jar
file and then both these into a J2EE application file (.ear). Deploying the .ear file is specific to the
applications server you are using.
For WebShere, instructions can be found at: