EJB Programming Using Weblogic
EJB Programming Using Weblogic
EJB Programming Using Weblogic
Server
Programming
WebLogic Enterprise JavaBeans
2. Designing EJBs
Designing Session Beans................................................................................... 2-1
Designing Entity Beans ..................................................................................... 2-2
Entity Bean Home Interface ....................................................................... 2-2
Make Entity EJBs Coarse-Grained............................................................. 2-2
Encapsulate Additional Business Logic in Entity EJBs ............................. 2-3
Optimize Entity EJB Data Access.............................................................. 2-3
Designing Message-Driven Beans..................................................................... 2-4
Using Inheritance with EJBs ............................................................................. 2-4
Accessing Deployed EJBs ................................................................................. 2-5
Differences Between Accessing EJBs from Local Clients and Remote Clients
2-6
Restrictions on Concurrency Access of EJB Instances .............................. 2-7
Storing EJB References in Home Handles................................................. 2-7
Using Home Handles Across a Firewall .................................................... 2-7
Preserving Transaction Resources..................................................................... 2-8
Allowing the Datastore to Manage Transactions ....................................... 2-9
Using Container-Managed Transactions Instead of Bean-Managed
Transactions for EJBs.......................................................................... 2-9
Never Demarcate Transactions from Application............................. 2-10
Always Use A Transactional Datasource for Container-Managed EJBs.
2-10
11. weblogic-cmp-rdbms-
This document describes how to develop and deploy Enterprise JavaBeans (EJBs) on
WebLogic Server. This document is organized as follows:
n Chapter 1, “Introducing WebLogic Server Enterprise JavaBeans,” is an overview
of EJB features supported in WebLogic Server.
n Chapter 2, “Designing EJBs,” is an overview of design techniques developers
can use to create EJBs.
n Chapter 3, “Using Message-Driven Beans,” explains how to develop and deploy
message-driven beans in the WebLogic Server container.
n Chapter 4, “The WebLogic Server EJB Container and Supported Services,”
describes the services available to the EJB with the WebLogic Services
container.
n Chapter 5, “WebLogic Server Container-Managed Persistence Services,”
describes the EJB container-managed persistence services available for entity
EJBs in the WebLogic Server container.
n Chapter 6, “Packaging EJBs for the WebLogic Server Container,” describes the
steps necessary to package EJBs for deployment to WebLogic Server.
n Chapter 7, “Deploying EJBs to WebLogic Server,” describes the process for
deploying EJBs in the EJB container.
n Chapter 9, “WebLogic Server EJB Utilities,” describes the utilities, shipped with
WebLogic Server, that are used with EJBs.
n Chapter 10, “weblogic-ejb-jar.xml Document Type Definitions,” describes the
WebLogic-specific deployment descriptors found in the
weblogic-ejb-jar.xml file shipped with WebLogic Server 6. 1.
Audience
This document is intended mainly for application developers who are interested in
developing Enterprise JavaBeans (EJBs) for use in dynamic Web-based applications.
Readers are assumed to be familiar with EJB architecture, XML coding, and Java
programming.
Contact Us!
Your feedback on the BEA WebLogic Server documentation is important to us. Send
us e-mail at [email protected] if you have questions or comments. Your
Documentation Conventions
The following documentation conventions are used throughout this document.
Convention Item
Ctrl+Tab Indicates that you must press two or more keys simultaneously.
monospace Indicates code samples, commands and their options, data structures
text and their members, data types, directories, and file names and their
extensions. Monospace text also indicates text that you must enter
from the keyboard.
Examples:
#include <iostream.h> void main ( ) the pointer psz
chmod u+w *
\tux\data\ap
.doc
tux.doc
BITMAP
float
1 Introducing WebLogic
Server Enterprise
JavaBeans
Note: WebLogic Server 6.1 is compliant with the Sun J2EE specification and EJB
1.1 specification. It also includes an implementation of the preliminary EJB
2.0 specification. Except where descriptions of EJB features and behaviors
make specific mention of EJB 1.1 or EJB 2.0, all information in this guide
relates to both implementation. You can deploy existing EJB 1.1 beans in this
version of WebLogic Server. However, if you are developing new beans, we
recommend that you develop EJB 2.0 beans.
The following sections provide an overview of the EJB features and introduce the
changes in the WebLogic Server 6.1 Enterprise JavaBeans implementation:
n EJB Roles
n EJB Enhancements in WebLogic Server
EJB Components
An EJB consists of three main components:
n Home interface. The EJB factory. Clients use this interface to create, find, and
remove EJB instances.
To create an EJB, you code a distributed application’s business logic into the EJB’s
implementation class; specify the deployment parameters in deployment descriptor
files; and package the EJB into a JAR file. You can then deploy the EJB individually
from a JAR file, or package it along with other EJBs and a Web application into an
EAR file, which you then deploy on WebLogic Server. Client applications can locate
the EJB and create an instance of the bean using the bean’s home interface. The client
can then invoke the methods of the EJB using the EJB’s remote interface. WebLogic
Server manages the EJB container and provides access to system-level services such
as database management, security management, and transaction services.
Types of EJBs
The EJB specification defines the following four types of Enterprise JavaBeans:
Note: Message driven beans are part of the Sun Microsystems EJB 2.0 specification.
They are not part of the EJB 1.1 specification.
Implementation of Preliminary
Specifications
The following sections describe the use of WebLogic Server with non-final
implementations of Java specifications.
n Enables an implementation of advanced J2EE 1.3 features along with the J2EE
1.2 features
n Enables the J2EE 1.2 features only, which is a fully compliant implementation of
the J2EE 1.2 specification
These two options comply with the rules governing J2EE. Both versions offer the same
container and differ only in the APIs that are available.
Sun Microsystem’s EJB 2.0 specification supports the following new features:
n New type of EJB called message-driven bean that is a Java Messaging Service
(JMS) consumer. See Chapter 3, “Using Message-Driven Beans,” for more
information.
n New entity EJB container-managed persistence model that provides a new way
of handling container-managed persistence. See Chapter 5, “WebLogic Server
Container-Managed Persistence Services,” for more information.
n New standard query language called EJB-QL which you use to query EJBs and
their properties. See Chapter 5, “WebLogic Server Container-Managed
Persistence Services,” for more information.
n New ejbSelect methods that allow an entity EJB to internally query for
properties using an EJB-QL query defined in a deployment descriptor. See
Chapter 5, “WebLogic Server Container-Managed Persistence Services,” for
more information.
n Local interfaces for session and entity beans. EJB relationships are now based on
the local interface. Any EJB that participates in a relationship must have a local
interface. See Chapter 5, “WebLogic Server Container-Managed Persistence
Services,” for more information.
n Home methods that allow you to execute a home business method that is not
specific to a particular instance of an entity bean. You use the home interface to
define one or more home methods for the entity bean See Chapter 2, “Designing
EJBs,” for more information.
EJB Roles
The process of developing EJBs is divided into the following distinct roles.
Application Roles
n Enterprise Bean Providers—Enterprise Bean Providers produce the EJBs.
Their output is the ejb.jar file that contains one or more EJBs. The providers
use the design process documented in this guide to design the EJBs that are
deployed in the WebLogic Server environment.
For more information on the design process, see Chapter 2, “Designing EJBs.”
Infrastructure Roles
n Container Providers—Container Providers supply EJB deployment tools,
container monitoring and management tools, and runtime support for deployed
EJB instances. This support includes services such as transaction and security
management, network distribution of clients, and scalability. The container
providers use the container management process documented in this guide to
provide the container.
For more information on the container management process, see Chapter 4, “The
WebLogic Server EJB Container and Supported Services.”
ejb-client.jar Support
Use the ejb-client.jar file to package required classes to compile the client into
one JAR file. The ejb-client.jar file contains the EJB interfaces necessary to call
an EJB. You specify that the WebLogic EJB compiler (weblogic.ejbc)
automatically create the ejb-client.jar file in the bean’s deployment descriptor
file. For more information on ejb-client .jar files, see “Specifying an
ejb-client.jar” on page 6-13.
For more information on using ANT utilities to create deployment descriptors, see
Packaging Enterprise JavaBeans at
http://e-docs.bea.com/wls/docs61/programming/packaging.html.
For more information, see Web Application Deployment Descriptor Editor Help at
http://e-docs.bea.com/wls/docs61/ConsoleHelp/webservices_ddehelp.
html.
XML Editor
The XML editor is a simple, user-friendly tool from Ensemble for creating and editing
XML files. It can validate XML code according to a specified DTD or XML Schema.
You can use the XML editor on Windows or Solaris machines and download it from
the BEA dev2dev at
http://dev2dev.bea.com/resourcelibrary/utilitiestools.jsp?highlight=utilitiestools.
2 Designing EJBs
The following sections provide guidelines for designing WebLogic Server Enterprise
JavaBeans (EJB)s. Some suggestions apply to remote object models and Remote
Method Invocation (RMI) as much as they do to EJB.
Have the model reside on the server, in the form of a session bean. (This is analogous
to having a servlet providing support for an HTML form, except that a model session
bean does not affect the final presentation.) There should be one model session bean
instance for each GUI form instance, which acts as the form’s representative on the
server. For example, if you have a list of 100 network nodes to display in a form, you
might have a method called getNetworkNodes() on the corresponding EJB that
returns an array of values relevant to that list.
This approach keeps the overall transaction time short, and requires minimal network
bandwidth. In contrast, consider an approach where the GUI form calls an entity EJB
finder method that retrieves references to 100 separate network nodes. For each
reference, the client must go back to the datastore to retrieve additional data, which
consumes considerable network bandwidth and may yield unacceptable performance.
n Use the create() methods to create new entity objects within the home.
n Use the finder() methods to find existing entity objects within the home.
n Use the remove() methods to remove an entity object from the home.
n Execute a home method that is not specific to a particular entity bean instance.
For example, cells in a spreadsheet are too fine-grained and should not be accessed
frequently over a network. In contrast, logical groupings of an invoice’s entries, or a
subset of cells in a spreadsheet can be modeled as an entity EJB, if additional business
logic is required for the data.
Entity EJBs should encapsulate additional business logic for the modeled data. For
example, a banking application that uses different business rules for “Platinum” and
“Gold” customers might model all customer accounts as entity EJBs; the EJB methods
can then apply the appropriate business logic when setting or retrieving data fields for
a particular customer type.
For bean-managed entity EJBs, the ejbCreate() method must return a primary key.
Any class that inherits from the bean-managed EJB class cannot have an
ejbCreate() method that returns a different primary key class than does the
bean-managed EJB class. This restriction applies even if the new class is derived from
the base EJB’s primary key class. The restriction also applies to the bean’s ejbFind()
method.
Also, EJBs inheriting from other EJB implementations change the interfaces. For
example, the following figure shows a situation where a derived bean adds a new
method that is meant to be accessible remotely:
Figure 2-1 Derived bean (BBean) adding new method to be accessible remotely
Bean Interface
ABean foo () ARemote foo ()
foo2 () foo2 ()
BBean BRemote
foo3 () extends ARemote foo3 ()
extends ABean
All EJBs must specify their environment properties using Java Naming and Directory
Interface (JNDI). You can configure the JNDI name spaces of EJB clients to include
the home EJBs that reside anywhere on the network — on multiple machines,
application servers, or containers.
However, in designing enterprise application systems, you must still consider the
effects of transmitting data across a network between EJBs and their clients. Because
of network overhead, it is still more efficient to access beans from a “local” client —
a servlet or another EJB — than to do so from a remote client where data must be
marshalled, transmitted over the network, and then unmarshalled.
...
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, url);
h.put(Context.SECURITY_PRINCIPAL, user);
If multiple servlet classes access a session EJB, each servlet thread (rather than each
instance of the servlet class) must have its own session EJB instance. To avoid
concurrent access, a JSP/servlet can use a stateful session bean in request scope.
A client can pass the HomeHandle object as arguments to another client, and the
receiving client can use the handle to obtain a reference to the same EJBHome object.
Clients can also serialize the HomeHandle and store it in a file for later use.
3. From the left pane, expand the Servers node and select a server.
6. Check the Reverse DNS Allowed box to enable reverse DNS lookups.
When you enable reverse DNS lookups, WebLogic Server stores the DNS name of the
server, rather than the IP address, in EJB home handles.
WebLogic Server can use a single connection pool to service multiple, simultaneous
database requests. The efficiency of the connection pool is largely determined by the
number and length of database transactions that use the pool. For non-transactional
database requests, WebLogic Server can allocate and deallocate a connection very
quickly, so that the same connection can be used by another client. However, for
transactional requests, a connection becomes “reserved” by the client for the duration
of the transaction.
To optimize transaction use on your system, always follow an “inside-out” approach
to transaction demarcation. Transactions should begin and end at the “inside” of the
system (the database) where possible, and move “outside” (toward the client
application) only as necessary. The following sections describe this rule in more detail.
n You define multiple transactions from within a single method call. WebLogic
Server demarcates transactions on a per-method basis.
Note: However, instead of using multiple transactions in a single method call, it
is better to break the method into multiple methods, with each of the
multiple methods having its own container-managed transaction.
n You define a single transaction that “spans” multiple EJB method calls. For
example, you define a stateful session EJB that uses one method to begin a
transaction, and another method to commit or roll back a transaction.
Note: Avoid this practice if possible because it requires detailed information
about the workings of the EJB object. However, if this scenario is required,
you must use bean-managed transaction coordination, and you must
coordinate client calls to the respective methods.
3 Using Message-Driven
Beans
The following sections describe how to develop message-driven beans and to deploy
then on WebLogic Server. Because message-driven beans use parts of the standard
JMS API, you should first become familiar with the WebLogic Java Messaging
Service (JMS) before attempting to implement message-driven beans. See the
Programming WebLogic JMS document for more information.
JMS destination, such as a topic or queue, at deployment time, and WebLogic Server
automatically creates and removes message-driven bean instances as needed to process
incoming messages.
The WebLogic Server container provides other standard EJB services to message-
driven beans, such as security services and automatic transaction management. These
services are described in more detail in “Transaction Management” on page 4-25 and
in “Using Transaction Services with Message-Driven Beans” on page 3-14.
Note: Only the WebLogic Server container directly interacts with a message-driven
bean by creating bean instances and passing JMS messages to those instances
as necessary.
To ensure concurrency, the container uses threads from the execute queue. The default
setting for the max-beans-in-free-pool deployment descriptor found in the
weblogic-ejb-jar.xml file provides the most parallelism. The only reason to change this
setting would be to limit the number of parallel consumers.
1. Create a source file (message-driven bean class) that implements both the
javax.ejb.MessageDrivenBean and javax.jms.MessageListener
interfaces.
The message-driven bean class must define the following methods:
l One ejbCreate() method that the container uses to create an instance of the
message-driven bean on the free pool.
l One onMessage() method that is called by the bean’s container when a
message is received. This method contains the business logic that handles
processing of the message.
l One ejbRemove() method that removes the message-driven bean instance
from the free pool.
For an example of output for a message-driven bean class, see “Message-Driven
Bean Class Requirements” on page 3-6
2. Specify the following XML deployment descriptor files for the message-driven
bean.
l ejb-jar.xml
l weblogic-ejb-jar.xml
l weblogic-cmp-rdbms-jar.xml
For instructions on specifying the XML files, see “Specifying and Editing the
EJB Deployment Descriptors” on page 6-5.
3. Set the message-driven element in the bean’s ejb-jar.xml file to declare the
bean.
4. Set the message-driven-destination element in the bean’s ejb-jar.xml file
to specify whether the bean is intended for a Topic or Queue.
6. If your bean will demarcate its own transaction boundaries, set the
acknowledge-mode sub-element to specify the JMS acknowledgment semantics
to use. This element has two possible values: AUTO_ACKNOWLEDGE (the default)
or DUPS_OK_ACKNOWLEDGE.
<message-driven>
<ejb-name>exampleMessageDriven1</ejb-name>
<ejb-class>examples.ejb20.message.MessageTraderBean</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>
javax.jms.Topic
</destination-type>
</message-driven-destination>
...
</message-driven>
...
</enterprise-beans>
<destination-jndi-name>...</destination-jndi-name>
</message-driven-descriptor>
10. Deploy the bean on WebLogic Server using the instructions in “Deploying
Compiled EJB Files” on page 7-9.
// final or abstract.
Make sure that the business logic accounts for asynchronous message processing. For
example, it cannot be assumed that the EJB receives messages in the order they were
sent by the client. Instance pooling within the container means that messages are not
received or processed in a sequential order, although individual onMessage() calls to
a given message-driven bean instance are serialized.
Set the permissions for the bean’s run-as principal to receive, as described below,
when connecting message-driven beans to the JMS destinations. This allows the
message-driven bean to connect to remote queues in the same domain or in another
domain as long as the same principal is defined in the other domain. WebLogic Server
uses the default guest user if you do not specify the run-as principal. However,
whether you use the run-as principal or guest, you must assign the receive
permission to the security principal.
To set the receive permission, you must first create a new access control list (ACL)
or modify an existing one. are lists of Users and Groups that have permission to access
the resources. Permissions are the privileges required to access resources, such as
permission to read, write, send, and receive files and load servlets, and link to libraries.
Note: Do not use the system user for message-driven beans that connect to JMS
destinations because system prevents the message-driven bean from
connecting to a destination in another domain.
See the following instructions to create the ACL, specify principals, and set
permissions:
3. In the right pane of the Administration Console, click the Create a New ACL
link.
The ACL Configuration window appears.
4. Specify the name of WebLogic Server resource that you want to protect with an
ACL in the New ACL Name field.
For example, create an ACL for a JMS destination named topic.
5. Click Create.
7. Specify the receive permission for the topic JMS destination resource.
9. Click Apply.
Note: If you are using message-driven beans instead of the standard JMS listeners to
handle messages, be advised that a given message-driven bean is associated
with only one topic. If your application requires a single JMS consumer to
service messages from multiple topics or queues, you must use a standard JMS
consumer or deploy multiple message-driven bean classes.
For instructions on specifying the XML files, see “Specifying and Editing the EJB
Deployment Descriptors” on page 6-5.
Handling Exceptions
Message-driven bean methods should not throw an application exception or a
RemoteException, even in onMessage(). If any method throws such an exception,
WebLogic Server immediately removes the EJB instance without calling
ejbRemove(). However, from the client perspective the EJB still exists, because
future messages are forwarded to a new bean instance that WebLogic Server creates.
2. If a bean instance is available in the free pool, WebLogic Server uses that
instance. If no bean instance is available in the free pool, because the
max-beans-in-free-pool attribute is at maxBeans (maximum setting),
WebLogic Server waits until a bean instance is free. See
“max-beans-in-free-pool” on page 10-45 for more information about this
attribute.
If no bean instance is located in the free pool, WebLogic Server creates a new
instance by calling the bean’s ejbCreate() method and then the bean’s
setMessageDrivenContext() to associate the instance with a container
context. The bean can use elements of this context as described in “Using the
Message-Driven Bean Context” on page 3-8.
As with other EJB types, the ejbCreate() method in the bean class should prepare
any resources that are required for the bean’s operation. The ejbRemove() method
should release those resources, so that they are freed before WebLogic Server removes
the instance.
Message-driven beans should also perform some form of regular clean-up routine
outside of the ejbRemove() method, because the beans cannot rely on ejbRemove()
being called under all circumstances (for example, if the EJB throws a runtime
exception).
The following sample code from the ejb-jar.xml file shows how to specify the
bean’s transaction context.
<container-transaction>
<method>
<ejb-name>MyMessageDrivenBeanQueueTx</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
</assembly-descriptor>
Message Receipts
The receipt of a JMS message that triggers a call to an EJB’s onMessage() method is
not generally included in the scope of a transaction. However, it is handled differently
for bean-managed and container-managed transactions.
n For EJBs that use bean-managed transactions, the message receipt is always
outside the scope of the bean’s transaction.
Message Acknowledgment
For message-driven beans that use container-managed transaction demarcation,
WebLogic Server automatically acknowledges a message when the EJB transaction
commits. If the EJB uses bean-managed transactions, both the receipt and the
acknowledgment of a message occur outside the EJB transaction context. WebLogic
Server automatically acknowledges messages for EJBs with bean-managed
transactions, but you can configure acknowledgment semantics using the
acknowledge-mode deployment descriptor element defined in the ejb-jar.xml file.
The following sections describe the WebLogic Server EJB container, various aspects
of EJB behavior in terms of the features and services that the container provides. See
to Chapter 5, “WebLogic Server Container-Managed Persistence Services,” for more
information on container-managed persistence (CMP).
n EJB Container
n Using max-beans-in-free-pool
n Transaction Management
n Resource Factories
EJB Container
The EJB container is a runtime container for the deployed EJBs that is automatically
created when WebLogic Server is started. During the entire life cycle of the entity
object, from its creations to removal, it lives in the container. The EJB container
provides a standard set of services, including caching, concurrency, persistence,
security, transaction management, locking, environment, memory replication,
environment, and clustering for the entity objects that live in the container.
You can deploy multiple entity beans in a single container. For each entity bean
deployed in a container, the container provides a home interface. The home interface
allows a client to create, find, and remove entity objects that belong to the entity bean
as well as execute home business methods which are not specific to a particular entity
bean object. A client can look up the entity bean’s home interface through JNDI. The
container is responsible for making the entity bean’s home interface available in the
JNDI name space. For instructions on looking up the home interface through JNDI, see
Programming WebLogic JNDI.
The following figure illustrates the WebLogic Server free pool, and the processes by
which stateless EJBs enter and leave the pool. Dotted lines indicate the “state” of the
EJB from the perspective of WebLogic Server.
Figure 4-1 WebLogic Server free pool showing stateless session EJB life cycle
Method complete
free pool
Client request
Client
Note: The maximum size of the free pool is limited either by available memory, or
the value of the max-beans-in-free-pool deployment element.
If all instances of an EJB class are active and max-beans-in-free-pool has been
reached, new clients requesting the EJB class will be blocked until an active EJB
completes a method call. If the transaction times out (or, for non-transactional calls, if
five minutes elapse), WebLogic Server throws a RemoteException.
The following figure illustrates the WebLogic Server cache, and the processes by
which stateful EJBs enter and leave the cache. Dotted lines indicate the state of the EJB
from the perspective of WebLogic Server.
Figure 4-2 WebLogic Server cache showing stateful session EJB life cycle
Passivation
cache
Activation
Client
Note: Stateful session EJBs must abide by certain rules to ensure that bean fields can
be serialized to persistent storage. See “Stateful Session EJB Requirements”
on page 4-7 for more information.
If max-beans-in-cache is reached and EJBs in the cache are not being used,
WebLogic Server passivates some of those beans. This occurs even if the unused beans
have not reached their idle-timeout-seconds limit. If max-beans-in-cache is
reached and all EJBs in the cache are being used by clients, WebLogic Server throws
a CacheFullException.
Note: When an EJB becomes eligible for passivation, it does not mean that
WebLogic Server passivates the bean immediately. In fact, the bean may not
be passivated at all. Passivation occurs only when the EJB is eligible for
passivation and there is pressure on server resources, or when WebLogic
Server performs regular cache maintenance.
You can specify the explicit passivation of stateful EJBs that have reached
idle-timeout-seconds by setting the cache-type element in the
weblogic-ejb-jar.xml file. This setting has two values: least recently used (LRU)
and not recently used (NRU). Specify LRU when you require more aggressive
passivation of EJBs. Specify NRU when you have memory pressures in the cache and
want to keep in memory the beans most in use by your client.
n For cached EJB instances: When WebLogic Server detects EJB classaes that are
approaching their max-beans-in-cache limit. Of those beans, WebLogic
Server takes EJB instances that have not been used for idle-timeout-seconds
and removes them from the cache (rather than passivating them to disk).
Removing, rather than passivating, the instance ensures that “inactive” EJBs do
not consume cache or disk resources in WebLogic Server.
If a stateful session bean is idle for longer than idle-timeout-seconds,
WebLogic Server may remove the instance from memory as regular cache
maintenance, even if the EJB class is max-beans-in-cache limit has not been
reached.
In addition, CMP entity beans can cache data during a finder query. So as with the
stateless session bean, only one query is performed.
Using max-beans-in-free-pool
In general, you should not set the max-beans-in-free-pool element. The only
reason to set max-beans-in-free-pool is to limit access to an underlying resource.
For example, if you use stateless session EJBs to implement a legacy connection pool,
you do not want to allocate more bean instances than the number of connections that
can support your legacy system. When you ask the free pool for a bean instance, there
are three possible scenarios that you can follow:
n Option 3: No instances are available in the pool and the number of instances in
use is already max-beans-in-free-pool. You wait until either your
transaction times out or a bean instance that already exists in the pool becomes
available.
n Entity Beans: WebLogic Server never pools instances for entity beans. Instead,
allow WebLogic Server to create a new instance.
n Stateless Session Beans: WebLogic Server always creates a new instance for
stateless session beans.
n Stateful Session Beans: Not applicable for stateful session beans. These beans
are not pooled.
1. A transaction is initiated for the entity EJB. The client may explicitly initiate a new
transaction and invoke the bean, or WebLogic Server may initiate a new transaction
in accordance with the bean’s method transaction attributes.
2. WebLogic Server calls ejbLoad() to read the most current version of the bean’s
persistent data from the underlying datastore.
This simple process of calling ejbLoad() and ejbStore() ensures that new
transactions always use the latest version of the EJB’s persistent data, and always write
the data back to the datastore upon committing. In certain circumstances, however, you
may want to limit calls to ejbLoad() and ejbStore() for performance reasons.
Alternately, you may want to call ejbStore() more frequently to view the
intermediate results of uncommitted transactions.
In the special circumstance where only a single WebLogic Server instance ever
accesses a particular EJB, calling ejbLoad() by default is unnecessary. Because no
other clients or systems update the EJB’s underlying data, WebLogic Server’s cached
version of the EJB data is always up-to-date. Calling ejbLoad() in this case simply
creates extra overhead for WebLogic Server clients that access the bean.
Do not set db-is-shared to “false” if you set the entity bean’s concurrency
strategy to the “Database” option. If you do, WebLogic Server will ignore the
db-is-shared setting.
With database locking specified, the EJB container continues to cache instances of
entity bean classes. However, the container does not cache the intermediate state of the
EJB instance between transactions. Instead, WebLogic Server calls ejbLoad() for
each instance at the beginning of a transaction to obtain the latest EJB data. This means
that setting db-is-shared to “false” which prevents WebLogic Server from calling
ejbload() at the beginning of each transaction is invalid.
The EJB provider or EJB deployment descriptors then identify the name of this method
by using the value of the is-modified-method-name element. WebLogic Server
calls the specified method name when a transaction commits, and calls ejbStore()
only if the method returns “true.” For more information on this element, see
“is-modified-method-name” on page 10-36.
If entity EJB updates appear “lost” in your system, start by ensuring that the value for
all is-modified-method-name elements return “true” under every circumstance. In
this way, you can revert to WebLogic Server’s default ejbStore() behavior and
possibly correct the problem.
If your datastore uses an isolation level of READ_UNCOMMITTED, you may want to allow
other database users to view the intermediate results of in-progress transactions. In this
case, the default WebLogic Server behavior of updating the datastore only at
transaction completion may be unacceptable. To do this, set
delay-updates-until-end-of-tx to “false.”
WebLogic Server never calls ejbStore() for a read-only entity EJB. ejbLoad() is
called initially when the EJB is created; afterwards, WebLogic Server calls
ejbLoad() only at intervals defined by the read-timeout-seconds deployment
parameter.
n They cannot require updates to the EJB data, because WebLogic Server never
calls ejbStore() for read-only entity EJBs.
n Their transaction attributes must be set to NotSupported (the beans cannot rely
on a transaction).
n The EJB’s method calls must be idempotent. See “Session EJBs in a Cluster” on
page 4-20 for more information.
n Because the bean’s underlying data may be updated by an external source, calls
to ejbLoad() are governed by the deployment parameter,
read-timeout-seconds.
The following example codes shows how to cast the home to CachingHome and then
call the method:
Figure 4-4 Sample code showing how to cast the home and call the method
import javax.naming.InitialContext;
import weblogic.ejb.CachingHome;
When the invalidate() method is called, the read-only entity beans are invalidated
in the local server, and a multicast message is sent to the other servers in the cluster to
invalidate their cached copies. The next call to an invalidated read-only entity bean
causes ejbLoad to be called. ejbLoad() reads the most current version of the
persistent data from the underlying datastore
WebLogic Server calls the invalidate() method after the transaction update has
completed. If the invalidation occurs during a transaction update, the previous version
may be read if the isolation level does not permit reading uncommitted data.
Read-Mostly Pattern
WebLogic Server does not support a read-mostly cache strategy setting in
weblogic-ejb-jar.xml. However, if you have EJB data that is only occasionally
updated, you can create a “read-mostly pattern” by implementing a combination of
read-only and read-write EJBs.
For an example of the read-mostly pattern, see the Read Mostly example in your
WebLogic Server distribution:
wlserver6.1\samples\examples\ejb\extensions\readMostly
When creating a read-mostly pattern, use the following suggestions to reduce data
consistency problems:
n For all read-only EJBs, set read-timeout-seconds to the same value for all
beans that may be updated in the same transaction.
n Ensure that all read-write EJBs in the system update only the smallest portion
of data necessary; avoid beans that write numerous, unchanged fields to the
datastore at each ejbStore().
n Ensure that all read-write EJBs update their data in a timely fashion; avoid
involving read-write beans in long-running transactions that may span the
read-timeout-seconds setting for their read-only counterparts.
Note: In a WebLogic Server cluster, clients of the read-only EJB benefit from
using cached EJB data. Clients of the read-write EJB benefit from true
transactional behavior, because the read-write EJB’s state always matches
the state of its data in the underlying datastore. See “Entity EJBs in a Cluster”
on page 4-23 for more information.
For read-write EJBs, WebLogic Server loads EJB data into the cache at the
beginning of each transaction, or as described in “Using db-is-shared to Limit Calls to
ejbLoad()” on page 4-10. WebLogic Server calls ejbStore() at the successful
commit of a transaction, or as described under “Using is-modified-method-name to
Limit Calls to ejbStore() (EJB 1.1 Only)” on page 4-11.
EJBs in a WebLogic Server cluster use modified versions of two key structures: the
Home object and the EJB object. In a single server (unclustered) environment, a client
looks up an EJB through the EJB’s home interface, which is backed on the server by a
corresponding Home object. After referencing the bean, the client interacts with the
bean’s methods through the remote interface, which is backed on the server by an EJB
object.
Note: Failover of EJBs work only between a remote client and the EJB.
All EJB types — stateless session, stateful session, and entity EJBs — can have
cluster-aware home stubs. Whether or not a cluster-aware home stub is created is
determined by the home-is-clusterable deployment element in
weblogic-ejb-jar.xml. If you set this element to “true” (the default), ejbc calls the
rmic compiler with the appropriate options to generate a cluster-aware home stub for
the EJB.
Server 1
Client EJBHome
EJBObject
obtain bean Home Home
Stub Server 2 Datastore
call method Remote Object EJBHome
Stub
EJBObject
Server 3
EJBHome commit
EJBObject
Clustered EJBObjects
In a WebLogic Server cluster, the server-side representation of the EJBObject can also
be replaced by a replica-aware EJBObject stub. This stub maintains knowledge about
all copies of the EJBObject that reside on servers in the cluster. The EJBObject stub
can provide load balancing and failover services for EJB method calls. For example, if
a client invokes an EJB method call on a particular WebLogic Server and the server
goes down, the EJBObject stub can failover the method call to another, running server.
Whether or not an EJB can use a replica-aware EJBObject stub depends on the type of
EJB deployed and, for entity EJBs, the cache strategy selected at deployment time.
This default behavior ensures that database updates within an EJB method are not
“duplicated” due to a failover scenario. For example, if a client calls a method that
increments a value in a datastore and WebLogic Server fails over to another server
before the method completes, the datastore would be updated twice for the client’s
single method call.
If methods are written in such a way that repeated calls to the same method do not
cause duplicate updates, the method is said to be “idempotent.” For idempotent
methods, WebLogic Server provides the
stateless-bean-methods-are-idempotent deployment property. If you set this
property to “true” in weblogic-ejb-jar.xml, WebLogic Server assumes that the
method is idempotent and will provide failover services for the EJB method, even if a
failure occurs during a method call.
The following figure show a stateless session EJBs in a WebLogic Server clustered
environment.
Server 1 failure
during
EJBHome method
Client EJBObject
Datastore
obtain bean Home Home Server 2
Stub EJBHome
commit
call method Remote Object EJBObject
Stub
Server 3
EJBHome
EJBObject
Each time a client of the EJB commits a transaction that modifies the EJB’s state,
WebLogic Server replicates the bean’s state to the secondary server instance.
Replication of the bean’s state occurs directly in memory, for best performance in a
clustered environment.
Should the primary server instance fail, the client’s next method invocation is
automatically transferred to the EJB instance on the secondary server. The secondary
server becomes the primary WebLogic Server for the EJB instance, and a new
secondary server handles possible additional failovers. Should the EJB’s secondary
server fail, WebLogic Server enlists a new secondary server instance from the cluster.
Clients of a stateful session EJB are therefore guaranteed to have quick access to the
latest committed state of the EJB, except under the special circumstances described in
“Limitations of In-Memory Replication” on page 4-23.
By default, WebLogic Server does not replicate the state of stateful session EJB
instances in a cluster. This models the behavior released with WebLogic Server
Version 6.0. To enable replication, set the replication-type deployment parameter
in the weblogic-ejb-jar.xml deployment file to InMemory.
...
<replication-type>InMemory</replication-type>
</stateful-session-clustering>
n Both the primary and secondary servers fail. The client needs to recreate the EJB
instance and restart the transaction.
Figure 4-9 shows read-write entity EJBs in a WebLogic Server clustered environment.
The three arrows on Home Stub point to all three servers and show multiple client
access.
Note: In the preceding figure, the set of three arrows for both home stubs refers to
the EJBHome on each server.
Cluster Address
When you configure a cluster, you supply a cluster address that identifies the Managed
Servers in the cluster. The cluster address is used in entity and stateless beans to
construct the host name portion of URLs. If the cluster address is not set, EJB handles
may not work properly. For more information on cluster addresses, see Using
WebLogic Server Clusters.
Transaction Management
The following sections provide information on how the EJB container supports
transaction management services. They describe EJBs in several transaction scenarios.
EJBs that engage in distributed transactions (transactions that make updates in
multiple datastores) guarantee that all branches of the transaction commit or roll back
as a logical unit.
The current version of WebLogic Server supports Java Transaction API (JTA), which
you can use to implement distributed transactional applications.
Also, two-phase commit is supported for both 1.1 and 2.0 EJBs. The two-phase
commit protocol is a method of coordinating a single transaction across two or more
resource managers. It guarantees data integrity by ensuring that transactional updates
are committed in all participating databases, or are fully rolled back out of all the
databases, reverting to the state prior to the start of the transaction. For more
information on using transactions and the two-phase commit protocol, see Introducing
Transactions.
Note: If the EJB provider does not specify a transaction attribute for a method in the
ejb-jar.xml file, WebLogic Server uses the supports attribute by default.
Using javax.transaction.UserTransaction
To define transaction boundaries in EJB or client code, you must obtain a
UserTransaction object and begin a transaction before you obtain a Java
Transaction Service (JTS) or JDBC database connection. If you start a transaction after
obtaining a database connection, the connection has no relationship to the new
transaction, and there are no semantics to “enlist” the connection in a subsequent
transaction context. If a JTS connection is not associated with a transaction context, it
operates similarly to a standard JDBC connection that has autocommit equal to true,
and updates are automatically committed to the datastore.
Once you create a database connection within a transaction context, that connection
becomes “reserved” until the transaction either commits or rolls back. To maintain
performance and throughput for your applications, always ensure that your transaction
completes quickly, so that the database connection can be released and made available
to other client requests. See “Preserving Transaction Resources” on page 2-8 for more
information.
Note: You can associate only a single database connection with an active transaction
context.
Figure 4-10 Sample Java Code setting user transaction isolation levels
import javax.transaction.Transaction;
import java.sql.Connection
import weblogic.transaction.TxHelper:
import weblogic.transaction.Transaction;
import weblogic.transaction.TxConstants;
ctx.lookup("javax.transaction.UserTransaction");
tx.begin();
Transaction tx = TxHelper.getTransaction();
tx.setProperty (TxConstants.ISOLATION_LEVEL, new Integer
(Connection.TRANSACTION_READ_COMMITED));
tx.commit();
Limitations of TRANSACTION_SERIALIZABLE
Many datastores provide limited support for detecting serialization problems, even for
a single user connection. Therefore, even if you set transaction-isolation to
TRANSACTION_SERIALIZABLE, you may experience serialization problems due to the
limitations of the datastore.
Refer to your RDBMS documentation for more details about isolation level support.
Even if you use the TRANSACTION_SERIALIZABLE setting for an EJB, you may receive
exceptions or rollbacks in the EJB client if contention occurs between clients for the
same rows. To avoid these problems, make sure that the code in your client application
catches and examines the SQL exceptions, and take you take the appropriate action to
resolve the exceptions, such as restarting the transaction.
With WebLogic Server, you can set the isolation level for transactions to
TRANSACTION_READ_COMMITTED_FOR_UPDATE for methods on which this option is
defined. When set, every SELECT query from that point on will have FOR_UPDATE
added to require locks on the selected data. This condition remains in effect until the
transaction does a COMMIT or ROLLBACK.
...
u = (UserTransaction)
jndiContext.lookup("javax.transaction.UserTransaction");
u.begin();
account1.withdraw(100);
account2.deposit(100);
u.commit();
...
In the above code fragment, updates performed by the “account1” and “account2”
EJBs occur within the context of a single UserTransaction. The EJBs commit or roll
back as a logical unit. This is true regardless of whether “account1” and “account2”
reside on the same WebLogic Server, multiple WebLogic Servers, or a WebLogic
Server cluster.
The only requirement for wrapping EJB calls in this manner is that both “account1”
and “account2” must support the client transaction. The beans’ trans-attribute
element must be set to Required, Supports, or Mandatory.
The “wrapper” EJB can explicitly obtain a transaction context before invoking other
EJBs, or WebLogic Server can automatically create a new transaction context, if the
EJB’s trans-attribute element is set to Required or RequiresNew. The
trans-attribute element is set in the ejb-jar.xml file. All EJBs invoked by the
wrapper EJB must be able to support the transaction context (their trans-attribute
elements must be set to Required, Supports, or Mandatory).
In some cases, a transaction can use EJBs that reside on multiple WebLogic Server
instances in a cluster. This can occur in heterogeneous clusters, where all EJBs have
not been deployed to all WebLogic Server instances. In these cases, WebLogic Server
uses a multitier connection to access the datastore, rather than multiple direct
connections. This approach uses fewer resources, and yields better performance for the
transaction.
However, for best performance, the cluster should be homogeneous — all EJBs should
reside on all available WebLogic Server instances.
Delay-Database-Insert-Until
By default, the database insert occurs after the client calls the ejbPostCreate
method. To delay having WebLogic Server insert the new bean, use the
delay-database-insert-until element in the weblogic-cmp-rdbms-jar.xml
file to specify the precise time at which a new bean that uses RDBMS CMP is inserted
into the database.
Delaying the database insert until after ejbPostCreate is required when a
cmr-field is mapped to a foreign-key column that does not allow null values. In
this case, set the cmr-field to a non-null value in ejbPostCreate before the bean
is inserted into the database.
Note: The cmr-fields may not be set during a ejbCreate method call, before the
primary key of the bean is known.
BEA recommend that you specify the delay the database insert until after
ejbPostCreate if the ejbPostCreate method modifies the persistent fields of the
bean. Doing so yields better performance by avoiding an unnecessary store operation.
Resource Factories
The following sections provide information on how the EJB container supports
resource services. In WebLogic Server, EJBs can access JDBC connection pools by
directly instantiating a JDBC pool driver. However, it is recommended that you instead
bind a JDBC datasource resource into the WebLogic Server JNDI tree as a resource
factory.
Using resource factories enables the EJB to map a resource factory reference in the
EJB deployment descriptor to an available resource factory in a running WebLogic
Server. Although the resource factory reference must define the type of resource
factory to use, the actual name of the resource is not specified until the bean is
deployed.
The following sections explain how to bind JDBC datasource and URL resources to
JNDI names in WebLogic Server.
6. Enter the Name, JNDI Name, and Pool Name. Check to enable Row Prefetch if
you if you want to prefetch rows between client and WebLogic Server for each
resultSet and then specify the Row Prefetch Size and Stream Chunk Size.
a. For non-transactional JDBC data sources, enter the full WebLogic Server
JNDI name to bind to the datasource and the name of the WebLogic Server
connection pool.
b. For transactional JDBC data sources, enter the full WebLogic Server JNDI
name to bind to the transactional datasource and the name of the WebLogic
Server connection pool.
For more information on configuring transactional and non-transactional data
sources, see Configure a JDBC Data Source.
8. Bind the JNDI name of the datasource to the EJB’s local JNDI environment by
doing one of the following:
Map an existing EJB resource factory reference to the JNDI name by directly
editing the resource-description element in the weblogic.ejb-jar.xml
deployment file. See “Specifying and Editing the EJB Deployment Descriptors”
on page 6-5 for instructions on editing deployment descriptors.
1. In a text editor, open the config.xml file for the instance of the WebLogic Server
you are using and set the URLResource attribute for the following config.xml
elements:
l WebServer
l VirtualHost:
2. Set the URLResource attribute for the WebServer element using the following
syntax:
<WebServer URLResource=”weblogic.httpd.url.testURL=http://
localhost:7701/testfile.txt” DefaultWebApp=”default-tests”/>
3. Set the URLResource attribute for the VirtualHost element, when virtual
hosting is required, using the following syntax:
<VirtualHostName=guestserver” targets=”myserver,test_web_server
“URLResource=”weblogic.httpd.url.testURL=http://
localhost:7701/testfile.txt” VirtualHostNames=”guest.com”/>
4. Save the changes in the config.xml file and reboot WebLogic Server
The EJB container in WebLogic Server can use exclusive locking mechanism for
entity EJB instances. As clients enlist an EJB or EJB method in a transaction,
WebLogic Server places an exclusive lock on the EJB instance for the duration of the
transaction. Other clients requesting the same EJB or method are blocked until the
current transaction completes.
With the database locking mechanism, the EJB container continues to cache instances
of entity EJB classes. However, the container does not cache the intermediate state of
the EJB instance between transactions. Instead, WebLogic Server calls ejbLoad() for
each instance at the beginning of a transaction to obtain the latest EJB data. The request
to commit data is subsequently passed along to the database. The database, therefore,
handles all lock management and deadlock detection for the EJB’s data.
Deferring locks to the underlying database improves throughput for concurrent access
to entity EJB data, while also providing deadlock detection. However, using database
locking requires more detailed knowledge of the underlying datastore’s lock policies,
which can reduce the EJB’s portability among different systems.
<entity-cache>
...
<concurrency-strategy>Database</concurrency-strategy>
</entity-cache>
...
</entity-descriptor>
5 WebLogic Server
Container-Managed
Persistence Services
n BLOB and CLOB DBMS Column Support for the Oracle DBMS
n Cascade Delete
n Tuned EJB 1.1 CMP Updates in WebLogic Server
n Primary Keys
n Automatic Primary Key Generation for EJB 2.0 CMP
n Groups
If an EJB will use container-managed persistence, you specify the type of persistence
services that the EJB uses in the weblogic-ejb-jar.xml deployment file. High-level
definitions for automatic persistence services are stored in the persistence-type and
persistence-use elements. The persistence-type element defines one or more
automatic services that the EJB can use. The persistence-use element defines
which service the EJB uses at deployment time.
n Query Language
l WebLogic Query Language (WLQL) for EJB 1.1 CMP
l WebLogic EJB-QL with WebLogic QL extension for EJB 2.0 CMP
(optional)
WebLogic Server provides an easy way to write finders. The EJB provider writes the
method signature of a finder in the EJBHome interface, and defines the finder’s query
expressions in the ejb-jar.xml deployment file.
ejbc creates implementations of the finder methods at deployment time, using the
queries in ejb-jar.xml.
The following sections explain how to write EJB finders using XML elements in
WebLogic Server deployment files.
Finder Signature
EJB providers specify finder method signatures using the form findMethodName().
Finder methods defined in weblogic-cmp-rdbms-jar.xml must return a Java
collection of EJB objects or a single object.
finder-list Stanza
The finder-list stanza associates one or more finder method signatures in EJBHome
with the queries used to retrieve EJB objects. The following is an example of a simple
finder-list stanza using WebLogic Server RDBMS-based persistence:
<finder-list>
<finder>
<method-name>findBigAccounts</method-name>
<method-params>
<method-param>double</method-param>
</method-params>
</finder>
</finder-list>
Note: If you use a non-primitive data type in a method-param element, you must
specify a fully qualified name. For example, use java.sql.Timestamp rather
than Timestamp. If you do not use a qualified name, ejbc generates an error
message when you compile the deployment unit.
finder-query Element
The finder-query element defines the WebLogic Query Language (WLQL)
expression used to query EJB objects from the RDBMS. WLQL uses a standard set of
operators against finder parameters, EJB attributes, and Java language expressions.
See “Using WebLogic Query Language (WLQL) for EJB 1.1 CMP” on page 5-6 for
more information on WLQL.
Note: Always define the text of the finder-query value using the XML CDATA
attribute. Using CDATA ensures that any special characters in the WLQL string
do not cause errors when the finder is compiled.
A CMP finder can load all beans using a single database query. So, 100 beans can be
loaded with a single database round trip. A bean-managed persistence (BMP) finder
must do one database round trip to get the primary key values of the beans selected by
the finder. As each bean is accessed, another database access is also typically required,
assuming the bean wasn’t already cached. So, to access 100 beans, a BMP might do
101 database accesses.
Note: For queries to 2.0 EJBs, see “Using EJB QL for EJB 2.0” on page 5-10. Using
the weblogic-ql query completely overrides the ejb-ql query.
Syntax
WLQL strings use the prefix notation for comparison operators:
(operator operand1 operand2)
Operators
The following are valid WLQL operators.
| Boolean or (| operand)
Operands
Valid WLQL operands include:
Note: You cannot use RDBMS column names as operands in WLQL. Instead,
use the EJB attribute (field) that maps to the RDBMS column, as defined
in the attribute-map in weblogic-cmp-rdbms-jar.xml.
n This example returns all EJBs that have the balance attribute greater than the
balanceGreaterThan parameter specified in the finder. The finder method
signature in EJBHome is:
public Enumeration findBigAccounts(double balanceGreaterThan)
throws FinderException, RemoteException;
The sample <finder> stanza is:
<finder>
<method-name>findBigAccounts</method-name>
<method-params>
<method-param>double</method-param>
</method-params>
<finder-query><![CDATA[(> balance $0)]]></finder-query>
</finder>
Note that you must define the balance field n the attribute map of the EJB’s
persistence deployment file.
Note: Always define the text of the finder-query value using the XML CDATA
attribute. Using CDATA ensures that any special characters in the WLQL string
do not cause errors when the finder is compiled.
n The following example shows how to use compound WLQL expressions. Also
note the use of single quotes (') to distinguish strings:
<finder-query><![CDATA[(& (> balance $0) (! (= accountType
'checking')))]]></finder-query>
n The following example finds all the EJBs in a table. It uses the sample finder
method signature:
public Enumeration findAllAccounts()
throws FinderException, RemoteException
The sample <finder> stanza uses an empty WLQL string:
<finder>
<method-name>findAllAccounts</method-name>
<finder-query></finder-query>
</finder>
n The following query finds all EJBs whose lastName field starts with “M”:
<finder-query><![CDATA[(like lastName M%)]]></finder-query>
n This query returns all EJBs that have a null firstName field:
<finder-query><![CDATA[(isNull firstName)]]></finder-query>
n This query returns all EJBs whose balance field is greater than 5000, and orders
the beans by the database column, id:
<finder-query><![CDATA[WHERE >5000 (orderBy 'id' (> balance
5000))]]></finder-query>
n This query is similar to the previous example, except that the EJBs are returned
in descending order:
<finder-query><![CDATA[(orderBy 'id desc' (>
))]]></finder-query>
SELECT DISTINCT
The EJB WebLogic QL extension SELECT DISTINCT tells your database to filter
duplicate queries. Using SELECT DISTINCT means that the EJB container’s
resources are not used to sort through duplicated results when SELECT DISTINCT is
specified in the EJB QL query.
ORDERBY
The EJB WebLogic QL extension ORDERBY is a keyword that works with the Finder
method to specify the CMP field selection sequence for your selections.
ORDERBY A.id
Note: ORDERBY defers all sorting to the DBMS. Thus, the order of the retrieved
result depends on the particular DBMS installation on top of which the bean is
running.
To use this option, declare a query that uses this feature in the weblogic-ql element.
This element is found in the weblogic-cmp-rdbms-jar.xml file. The weblogic-ql
element specifies a query that contains a WebLogic specific extension to the EJB-QL
language.
This statement generates the following SQL with the optimizer hint for Oracle:
SELECT /*+ INDEX_ASC(myindex) */ column1 FROM .... (etc)
Using BLOB or CLOB may slow performance because of the size of the BLOB or
CLOB object.
</field-map>
</field-map>
Cascade Delete
Use the cascade delete mechanism to remove entity bean objects. When cascade delete
is specified for a particular relationship, the lifetime of one entity object depends on
another. You can specify cascade delete for one-to-one and one-to-many relationships;
many-to-many relationships are not supported. The cascade delete() method uses
the delete features in WebLogic Server, and the database cascade delete()
method instructs WebLogic Server to use the underlying database’s built-in support
for cascade delete.
To enable this feature, you must recompile the bean code for the changes to the
deployment descriptors to take effect.
Specify cascade delete using the cascade-delete element in the ejb-jar.xml file
as follows:
dname VARCHAR2(9) );
ename VARCHAR2(10),
REFERENCES dept(deptno)
ON DELETE CASCADE );
This feature is enabled for EJB 2.0 CMP, by default. To enable tuned EJB 1.1 CMP
updates, make sure that you set the following deployment descriptor element in the
weblogic-cmp-rdbms-jar.xml file to true.
<enable-tuned-updates>true</enable-tuned-updates>
You can disable tuned CMP updates by setting this deployment descriptor element as
follows:
<enable-tuned-updates>false</enable-tuned-updates>
If this option is turned off, which is the default behavior, the results of the current
transactions are not reflected in the query. If this option is turned on, the container
flushes all changes for cached transactions written to the database before executing the
new query. This way, the changes show up in the results.
The default is false, which provides the best performance. Updates made to the
cached transaction are reflected in the result of a query; no changes are written to the
database, and you do not see the changes in the query result.
Whether you use this feature depends on whether performance is more important than
current and consistent data.
Primary Keys
The primary key is an object that uniquely identifies an entity bean within its home.
The container must be able to manipulate the primary key of an entity bean. Each entity
bean class may define a different class for its primary key, but multiple entity beans
can use the same primary key class. The primary key is specified in the deployment
descriptor for the entity bean. You can specify a primary key class for an entity bean
with container-managed persistence by mapping the primary key to either a single field
or to multiple fields in the entity bean class.
Every entity object has a unique identity within its home. If two entity objects have the
same home and the same primary key, they are considered identical. A client can
invoke the getPrimaryKey() method on the reference to an entity object’s remote
interface to determine the entity object’s identity within its home. The object identify
associated with the a reference does not change during the lifetime of the reference.
Therefore, the getPrimaryKey() method always returns the same value when called
on the same entity object reference. A client that knows the primary key of an entity
object can obtain a reference to the entity object by invoking the
findByPrimaryKey(key) method on the bean’s home interface.
the class name in this deployment descriptor element. All fields in the primary key
class must be declared public. The fields in the class must have the same name as the
primary key fields in the ejb-jar.xml file.
n Do not construct a new primary key class with an ejbCreate. Instead, allow the
container to create the primary key class internally.
n Set the values of the primary key cmp-fields using the setXXX methods within
the ejbCreate method.
n Do not use a cmp field of the type BigDecimal as a primary key field for CMP
beans. The boolean BigDecimal.equals (object x) method considers two
BigDecimal equal only if they are equal in value and scale. This is because
there are differences in precision between the Java language and different
databases. For example, the method does not consider 7.1 and 7.10 to be equal.
Consequently, this method will most likely return false or cause the CMP bean
to fail.
If you need to use BigDecimal as the primary key, you should:
Note: This feature is supported for the EJB 2.0 CMP container only, there is no
automatic primary key generation support for EJB 1.1 CMP. For 1.1 beans,
you must use bean-managed-persistence (BMP.)
Note: For instructions on creating a table in Oracle, use the Oracle database
documentation.
At this time, WebLogic Server only provides DBMS primary key generation support
for Oracle and Microsoft SQL Server. However, you can use named/sequence tables
with other unsupported databases. Also, this feature is intended for use with simple
(non-compound) primary keys.
n java.lang.Integer
Once the SEQUENCE already exists in the database, you specify automatic key
generation in the XML deployment descriptors. In the
weblogic-cmp-rdbms-jar.xml file, you specify automatic key generation as
follows:
<key-cache-size>10</key-cache-size>
</automatic-key-generation>
Specify the name of the ORACLE SEQUENCE to be used, using the generator-name
element. If the ORACLE SEQUENCE was created with a SEQUENCE INCREMENT value,
then you must specify a key-cache-size. This value must match the Oracle
SEQUENCE INCREMENT value. If these two values are different, then you will most
likely have duplicate key problems.
Note: For instructions on creating a table in Microsoft SQL Server, see the Microsoft
SQL Server database documentation.
Once the IDENTITY column is created in the database table, you specify automatic key
generation in the XML deployment descriptors. In the
weblogic-cmp-rdbms-jar.xml file, you specify automatic key generation as
follows:
The generator-type element lets you specify the primary key generation method
that you want to use.
Note: For instructions on creating the table, see the documentation for the specific
database product.
Once the NAMED_SEQUENCE_TABLE exists in the database, you specify automatic key
generation by using the XML deployment descriptors in the
weblogic-cmp-rdbms-jar.xml file, as follows:
Figure 5-9 Specifying automatic key generation for named sequence table
support
<automatic-key-generation>
<generator-type>NAMED_SEQUENCE_TABLE</generator-type>
<generator_name>MY_SEQUENCE_TABLE_NAME</generator-name>
<key-cache-size>100</key-cache-size>
</automatic-key-generation>
Specify the name of the SEQUENCE TABLE to be used, with the generator-name
element. Using the key-cache-size element, specify the optional size of the key
cache that tells you how many keys the container will fetch in a single DBMS call.
For improved performance, BEA recommends that you set this value to >1, a number
greater than one. This setting reduces the number of calls to the database to fetch the
next key value.
Also, it is recommended that you define one NAMED SEQUENCE table per bean type.
Beans of different types should not share a common NAMED SEQUENCE table. This
reduces contention for the key table.
WebLogic Server makes a best attempt to create the new table. However, if based on
the descriptions in the deployment files, the field cannot be successfully mapped to an
appropriate column type in the database, the TABLE CREATION fails, an error is thrown,
and you must create the table yourself.
Because automatic table creation may not map every Java field type successfully to
your target database, the following list is provided to give you an idea of the type of
mapping you can expect to see.
boolean INTEGER
byte INTEGER
char CHAR
float FLOAT
int INTEGER
long INTEGER
short INTEGER
java.lang.Boolean INTEGER
java.lang.Byte INTEGER
java.lang.Float FLOAT
java.lang.Integer INTEGER
java.lang.Long INTEGER
java.lang.Short INTEGER
java.sql.Date DATE
java.sql.Time DATE
java.sql.Timestamp DATETIME
Container-Managed Persistence
Relationships
The entity bean relies on container-managed persistence to generate the methods that
perform persistent data access for the entity bean instances. The generated methods
transfer data between entity bean instances and the underlying resource manager.
Persistence is handled by the container at runtime. The advantage of using
container-managed persistence is that the entity bean can be logically independent of
the data source in which the entity is stored. The container manages the mapping
between the logical and physical relationships at runtime and manages their referential
integrity.
Persistent fields and relationships make up the entity bean’s abstract persistence
schema. The deployment descriptors indicate that the entity bean uses
container-managed persistence, and these descriptors are used as input to the container
for data access.
Entity beans can have relationships with other beans. These relationships can be either
bidirectional or unidirectional.
WebLogic Server supports three types of relationship mappings that are managed by
WebLogic container-managed persistence (CMP):
n One-to-one
n One-to-many
n Many-to-many
One-to-One Relationships
A WebLogic Server one-to-one relationship also involves the physical mapping from
a foreign key in one bean to the primary key in another bean. See “Groups” on page
5-32 for more information on primary keys.
One-to-Many Relationships
A WebLogic Server one-to-many relationship also involves the physical mapping
from a foreign key in one bean to the primary key of another. However, in a
one-to-many relationship, the foreign key is always contained in the role that occupies
the “many” side of the relationship.
Many-to-Many Relationships
A WebLogic Server many-to-many relationship involves the physical mapping of a
join table. Each row in the join table contains two foreign keys that map to the primary
keys of the entities involved in the relationship.
Unidirectional Relationships
Unidrectional relationships can only navigate in one direction. These types of
relationships are used with remote beans, and only unidirectional relationships can be
remote. A remote bean is one whose abstract persistence schema is not defined in the
same EJB-jar file as the bean with which it has a relationship. For example, if entity
A and entity B are in a one-to-one, unidirectional relationship and the direction is from
entity A to entity B, than entity A is aware of entity B, but entity B is unaware of entity
A. This type of relationship is implemented with a CMR-field on the entity bean from
which navigation can take place and no related CMR-field on the target entity bean.
Bidirectional Relationships
Bidirectional relationships can be navigated in both directions. These types of
container-managed relationships can exist only between beans whose abstract
persistence schemas are defined in the same EJB-jar file and therefore managed by
the same container. For example, if entity A and entity B are in a one-to-one
bidirectional relationship, both are aware of each other.
Local Interfaces
WebLogic Server provides support for local interfaces for session and entity beans.
Local interfaces allow enterprise javabeans to work together within the same EJB
container using different semantics and execution contexts. The EJBs are usually
co-located within the same EJB container and execute within the same Java Virtual
Machine (JVM). This way, they do not use the network to communicate and avoid the
over-head of a Java Remote Method Invocation-Internet Inter-ORB Protocol
(RMI-IIOP) connection.
EJB relationships with container-managed persistence are now based on the EJB’s
local interface. Any EJB that participates in a relationship must have a local interface.
Local interface objects are lightweight persistent objects. They allow you to do more
fine grade coding than do remote objects. Local interfaces also use pass-by-reference.
The getter is in the local interface.
The EJB container makes the local home interface accessible to local clients through
JNDI. To reference a local interface you need to have a local JNDI name. The objects
that implement the entity beans’ local home interface are called EJBLocalHome
objects.
A local client accesses a session or entity bean through the bean’s local interface and
local home interfaces. The container provides classes that implement the bean’s local
and local home interfaces. The objects that implement these interfaces are local Java
objects. The following diagram shows the container with a local client and local
interfaces.
Container
EJB Objects
EJB Home
Client EJB 1
EJB LocalObjects
EJB LocalHome
EJB 2
WebLogic Server provides support for both local and uni-directional remote
relationships between EJBs. If the EJBs are on the same server and are part of the same
JAR file, they can have local relationships. If the EJBs are not on the same server, the
relationships must be remote. For a relationship between local beans, multiple column
mappings are specified if the key implementing the relation is a compound key. For a
remote bean, only a single column-map is specified, since the primary key of the
remote bean is opaque. No column-maps are specified if the role just specifies a
group-name. No group-name is specified if the relationship is remote.
n New model for handling exceptions that propagates the correct exception to the
client.
Groups
In container-managed persistence, you use groups to specify certain persistent
attributes of an entity bean. A field-group represents a subset of the cmp and
CMR-fields of a bean. You can put related fields in a bean into groups that are faulted
into memory together as a unit. You can associate a group with a query or relationship,
so that when a bean is loaded as the result of executing a query or following a
relationship, only the fields mentioned in the group are loaded.
A special group named “default” is used for queries and relationships that have no
group specified. By default, the default group contains all of a bean's CMP-fields and
any CMR-fields that add a foreign key to the persistent state of the bean.
A field can belong to multiple groups. In this case, the getXXX() method for the field
will fault in the first group that contains the field.
You use field groups when you want to access a subset of fields.
boolean SMALLINT
byte SMALLINT
char SMALLINT
double NUMBER
float NUMBER
int INTEGER
long NUMBER
short SMALLINT
java.lang.String VARCHAR/VARCHAR2
java.lang.Boolean SMALLINT
java.lang.Byte SMALLINT
java.lang.Character SMALLINT
java.lang.Double NUMBER
java.lang.Float NUMBER
java.lang.Integer INTEGER
java.lang.Long NUMBER
java.lang.Short SMALLINT
java.sql.Date DATE
java.sql.Time DATE
java.sql.Timestamp DATE
java.math.BigDecimal NUMBER
Do not use the SQL CHAR data type for database columns that are mapped to CMP
fields. This is especially important for fields that are part of the primary key, because
padding blanks that are returned by the JDBC driver can cause equality comparisons
to fail when they should not. Use the SQL VARCHAR data type instead of SQL
CHAR.
A CMP field of type byte[] cannot be used as a primary key unless it is wrapped in a
user-defined primary key class that provides meaningful equals() and hashCode()
methods. This is because the byte[] class does not provide useful equals and
hashCode.
The following sections describe how to package EJBs into a WebLogic Server
container for deployment. They includes a description of the contents of a deployment
package, including the source files, deployment descriptors, and the deployment mode.
n Specifying an ejb-client.jar
n Manifest Class-Path
Component Description
Bean Class The bean class implements the bean’s business and life cycle
methods.
Remote Interface The remote interface defines the beans’s business logic that can
be access from applications outside of the bean’s EJB container.
Remote Home Interface The remote home interface defines the bean’s file cycle methods
that can be accessed from applications outside of the bean’s EJB
container.
Local Interface The local interface defines the bean’s business methods that can
be used by other beans that are co-located in the same EJB
container.
Component Description
Local Home Interface The local home interface defines the bean’s life cycle methods
that can be used by other beans that are co-located in the same
EJB container.
Primary Key The primary key class provides a pointer into the database. Only
entity beans need a primary key.
The deployment files become part of the EJB deployment when the bean is compiled.
The XML deployment descriptor files should contain the minimum deployment
descriptor settings for the EJB. Once the file exists, it can later be edited using the
instructions in “Specifying and Editing the EJB Deployment Descriptors” on page 6-5.
The deployment descriptor files must conform to the correct version of the Document
Type Definition (DTD) for each file you use. All element and sub element (attribute)
names for each of the EJB XML deployment descriptor files are described in the file’s
Document Type Definition (DTD) file. For a description of each file, see the following
sections.
ejb-jar.xml
The ejb-jar.xml file contains the Sun Microsystem-specific EJB DTD. The
deployment descriptors in this file describe the enterprise bean’s structure and declares
its internal dependences and the application assembly information, which describes
how the enterprise bean in the ejb-jar file is assembled into an application
deployment unit. For a description of the elements in this file, see the JavaSoft
specification.
weblogic-ejb-jar.xml
The weblogic-ejb-jar.xml file contains the WebLogic Server-specific EJB DTD
that defines the caching, clustering, and performance behavior of EJBs. It also contains
descriptors that map available WebLogic Server resources to EJBs. WebLogic Server
resources include security role names and data sources such as JDBC pools, JMS
connection factories, and other deployed EJBs. For a description of the elements in this
file, see Chapter 10, “weblogic-ejb-jar.xml Document Type Definitions.”
weblogic-cmp-rdbms.xml
The weblogic-cmp-rdbms.xml file contains the WebLogic Server-specific EJB
DTD that defines container-managed persistence services. Use this file to specify how
the container handles synchronizing the entity beans’s instance fields with the data in
the database. For a description of the elements in this file, see Chapter 11,
“weblogic-cmp-rdbms- jar.xml Document Type Definitions.”
Figure 6-1 The relationship among the components of the deployment files.
WebLogic Server
ejb-jar.xml
<assembly-descriptor>
<security-role>. . .
</assembly-descriptor> Principal
<entity>
<ejb-name>. . . JDBC Pool
<ejb-ref>. . .
JMS
</entity>
EJB
weblogic-ejb-jar.xml
<security-role-assignment>. . .
<weblogic-enterprise-bean>
<ejb-name>. . .
<caching-descriptor>. . .
<clustering-descriptor>. . .
<resource-descriptor>. . .
<reference-descriptor>. . .
<persistence-descriptor>. . . weblogic-cmp-rdbms-jar.xml
</ejb-name> <weblogic-rdbms-bean>
</weblogic-enterprise-bean> ...
</weblogic-rdbms-bean>
1. Use an ASCII text editor that does not reformat the XML or insert additional
characters that could invalidate the file.
2. Open the XML deployment descriptor file that you want to edit.
3. Type in your changes. Use the correct case for file and directory names, even if
your operating system ignores the case.
4. To use the default value for an optional element, either omit the entire element
definition or specify a blank value, as in:
<max-beans-in-cache></max-beans-in-cache>
2. Start the Administration Console and select EJB from the right pane.
3. In the left pane, choose the Deployments node under your server domain.
4. Expand the Deployments node and choose EJB.
5. From the expanded list of deployed EJBs, right-click on the bean to be edited.
8. Expand the node for the deployment descriptors that you want to edit.
The current settings for the deployment descriptor file that you selected appear
in the left pane. When you right-click on an item in the list, a dialog window for
that item appears in the right pane.
9. Clicking on the circles displays a dialog window in the right pane with various
settings.
You can change the settings in the dialog window to edit those deployment
descriptors.
10. Clicking on the folders displays tables in the right pane where you can view your
settings.
Here you can usually configure a new descriptor or customize your view of the
existing settings. If an item in the table is underlined, you can click on it to
display a dialog where you can change the settings.
11. By right-clicking on deployment descriptor items in the right pane, you can also
delete descriptors.
Note: For more information on the EJB deployment descriptors, see either the online
help in the Administration Console or Chapter 10, “weblogic-ejb-jar.xml
Document Type Definitions,” and Chapter 11, “weblogic-cmp-rdbms- jar.xml
Document Type Definitions.”
WebLogic Server also checks the contents of applications every ten seconds to
determine whether an EJB deployment has changed. If a deployment has changed, it
is automatically redeployed using the dynamic deployment feature.
To enable this mode, at the command line set the following to true:
-d production mode enabled true
For more information on this production mode, see “Starting the WebLogic
Administration Server from the Command Line” in startstop.html of the
Administration Guide.
The EJB provider should also supply an EJB compliant ejb-jar.xml file that
describes the bundled EJB(s). The ejb-jar.xml file and any other required XML
deployment file must reside in a top-level META-INF subdirectory of the JAR or
deployment directory. The following diagram shows the first stage of packaging the
the EJB and the deployment descriptor files into a deployment directory or JAR file.
Figure 6-2 Packaging the EJB classes and deployment descriptors into a
deployment directory
JAR file or deployment directory JAR file or deployment directory
ejb-jar.xml weblogic-ejb-jar.xml
weblogic-cmp-rdbms-jar.xml
As is, the basic JAR or deployment directory cannot be deployed to WebLogic Server.
You must first create and configure the WebLogic-specific deployment descriptor
elements in the weblogic-ejb-jar.xml file, and add that file to the deployment
directory or ejb.jar file. For more information on creating the deployment descriptor
files, see “WebLogic Server EJB Deployment Files” on page 6-3.
If you are deploying an entity EJB that uses container-managed persistence, you must
also add the WebLogic -specific deployment descriptor elements for the bean’s
persistence type. For WebLogic Server container-managed persistence (CMP)
services, the file is generally named weblogic-cmp-rdbms-jar.xml. You require
a separate file for each bean that uses CMP. If you use a third-party persistence vendor,
the file type as well as its contents may be different from
weblogic-cmp-rdbms-jar.xml; refer to your persistence vendor’s documentation
for details.
If you do not have any of the deployment descriptor files needed for your EJB, you
must manually create one. The best method is to copy an existing file and edit the
settings to conform to the needs of your EJB. Use the instructions in “Specifying and
Editing the EJB Deployment Descriptors” on page 6-5 to create the files.
ejb.jar file
You create the ejb.jar file with the Java Jar utility (javac). This utility bundles the
EJB classes and deployment descriptors into a single Java ARchive (JAR) file that
maintains the directory structure. The ejb-jar file is the unit that you deploy to
WebLogic Server.
1. Compile the EJB classes using javac compiler from the command line.
2. Add the appropriate XML deployment descriptor files to the compiled unit using
the guidelines in “WebLogic Server EJB Deployment Files” on page 6-3.
3. Generate the container classes that are used to access the bean using ejbc.
Container classes include both the internal representation of the EJB that
WebLogic Server uses, as well as implementation of the external interfaces
(home, local, and/or remote) that clients use.
The following figure shows the container classes added to the deployment unit when
the JAR file is generated
ejbPSWeblogic_CMP_RDBMS.class
ejb-jar.xml
weblogic-ejb-jar.xml
weblogic-cmp-rdbms-jar.xml
Once you have generated the deployment unit, you can designate the file extension as
either a JAR, EAR, or WAR archive.
automatically creates two new classloaders: one for EJBs and one for Web
applications. The EJB classloader is a child of the Java system classloader and the Web
application classloader is a child of the EJB classloader.
Specifying an ejb-client.jar
WebLogic Server supports the use of ejb-client.jar files. Create an
ejb-client.jar file by specify this feature in the bean’s ejb-jar.xml deployment
descriptor file and then generating the ejb-client.jar file using weblogic.ejbc.
An ejb-client.jar contains the class files that a client program needs to call the
EJBs contained in the ejb-jar file. The files are the classes required to compile the
client. If you specify this feature, WebLogic Server automatically creates the
ejb-client.jar.
To specify an ejb-client.jar:
1. Compile the bean’s Java classes into a directory, using the javac compiler from
the command line.
2. Add the EJB XML deployment descriptor files to the compiled unit using the
guidelines in “WebLogic Server EJB Deployment Files” on page 6-3.
4. Generate the container classes that are used to access the bean using
weblogic.ejbc and create the ejb-client.jar using the following
command:
$ java weblogic.ejbc <ShoppingCart.jar>
<ShoppingCart.jar>
Container classes include both the internal representation of the EJB that
WebLogic Server uses, as well as implementation of the external interfaces
(home, local, and/or remote) that clients use.
The ejb-client.jar always contains the home and remote interfaces and the
primary key class, for entity beans. Also, it contains a copy of any classes from the
ejb-jar file that are referenced by these interfaces. For example, the ShoppingCart
remote interface might have a method that returns an Item class. Because this remote
interface references this class, and it is located in the ejb-jar file, it will be included
in the EJB client.jar.
External clients can include the ejb-client.jar in their classpath. Web applications
would include the ejb-client.jar in their /lib directory.
Manifest Class-Path
Use the manifest file to specify that a JAR file can reference another JAR file.
Standalone EJBs cannot use the Manifest Class-Path. It is only supported for
components that are deployed within an EAR file. The clients should reference the
client.jar in the classpath entry of the manifest file.
1. Specify the name of the referenced JAR file in a Class-Path header in the
referencing JAR file’s Manifest file.
The referenced JAR file is named using a URL relative to the URL of the
referencing JAR file.
To place the home/remote interfaces for the EJB in the classpath of the calling
component:
3. Place the client.jar, along with all the clients of the bean in an EAR.
7 Deploying EJBs to
WebLogic Server
The following sections provides instructions for deploying EJBs to WebLogic Server
at WebLogic Server startup or on a running WebLogic Server.
n Application assemblers who link multiple EJBs and EJB resources to create
larger Web application systems
n EJB developers who create and configure new EJB JAR files
You can create, modify, and deploy EJBs in one or more instance of WebLogic Server.
You can set up your EJB deployment, and map EJB references to actual resource
factories, roles, and other EJBs available on a server by editing the XML deployment
descriptor files.
1. Follow the instructions in to ensure that your deployable EJB JAR file or
deployment directory contains the required WebLogic Server XML deployment
files.
2. Use a text editor or the EJB Deployment Descriptor Editor in the Administration
Console to edit the XML deployment descriptor elements, as necessary.
If your EJB JAR file is located in a different directory, make sure that you copy
it to this directory if you want to deploy it at startup.
n Update a deployed EJB implementation class to fix a bug or test a new feature
Whether you deploy or update the EJB from the command line or the Administration
Console, you use the automatic deployment features. The following sections describe
automatic deployment concepts and procedures.
When you deploy an EJB, WebLogic Server implicitly assigns a deployment name that
matches the path and filename of the JAR file or deployment directory. You can use
this assigned name to undeploy or update the bean after the server has started.
Note: The EJB deployment name remains active in WebLogic Server until the server
is rebooted. Undeploying an EJB does not remove the associated deployment
name, because you may later re-use that name to deploy the bean.
where:
n name is the string you want to assign to this EJB deployment unit
n source is the full path and filename of the EJB JAR file you want to deploy, or
the full path of the EJB deployment directory
For example:
% java weblogic.deploy -port 7001 -host localhost deploy
weblogicpwd CMP_example
c:\weblogic\myserver\unjarred\containerManaged\
During deployment, the uncompiled EJB is copied to each server instance in the
cluster, but it is compiled only on the server instance to which it has been deployed. As
a result, the server instances in the cluster to which the EJB was not targeted lack the
classes generated during compilation that are necessary to invoke the EJB. When a
client on another server instance tries to invoke the pinned EJB, it fails, and an
Assertion error is thrown in the RMI layer.
1. To list the EJBs that are deployed on a local WebLogic Server, enter the following:
% java weblogic.deploy list password
where password is the password for the WebLogic Server System account.
2. To list deployed EJBs on a remote server, specify the port and host options as
follows:
% java weblogic.deploy -port port_number -host host_name
list password
Undeployment does not automatically remove the specified EJB’s public interface
classes. Implementations of the home interface, remote interface, and any support
classes referenced in the public interfaces, remain in the server until all references to
those classes are released. At that point, the public classes may be removed due to
normal Java garbage collection routines.
Similarly, undeploying an EJB does not remove the deployment name associated with
the ejb.jar file or deployment directory. The deployment name remains in the server
to allow for later updates of the EJB.
Undeploying EJBs
To undeploy a deployed EJB, use the following steps:
1. Choose EJB from the Deployments node in the left pane of the Console.
3. Choose the Configuration tab from the dialog in the right pane and uncheck the
undeploy box.
Undeploying an EJB does not remove the EJB deployment name from WebLogic
Server. The EJB remains undeployed for the duration of the server session, as long as
you do not change it once it had been undeployed. You cannot re-use the deployment
name with the deploy argument until you reboot the server. You can re-use the
deployment name to update the deployment, as described in the following section.
n You reboot the server (if the JAR or directory is to be automatically deployed),
or
When clients next acquire a reference to the EJB, their EJB method calls use the
updated EJB implementation classes.
Note: You can update only the EJB implementation classes, as described in
“Loading EJB Classes into WebLogic Server” on page 6-12. You cannot
update the EJB’s public interfaces, or any support classes that are used by the
public interfaces. If you make any changes to the EJB’s public classes and
attempt to update the EJB, WebLogic Server displays an incompatible class
change error when a client next uses the EJB instance.
Use the update argument and specify the active EJB deployment name:
% java weblogic.deploy -port 7001 -host localhost update
weblogicpwd CMP_example
1. Choose EJB from the Deployments node in the left pane of the Console.
3. Choose the Configuration tab from the dialog in the right pane and update the
EJB by checking the deployed box.
You can update only the EJB implementation class, not the public interfaces or public
support classes
2. Package the EJB classes and interfaces into a valid JAR or EAR file.
3. Use the weblogic.ejbc compiler on the JAR file to generate WebLogic Server
container classes. For instructions on using ejbc, see “ejbc” on page 9-1.
n You do not have to use weblogic.ejbc on the packaged JAR file to generate
WebLogic Server container classes.
The .java or .class files in the JAR file must still be packaged in subdirectories that
match their Java package hierarchy. Also, as with all ejb.jar files, you must include
the appropriate XML deployment files in a top-level META-INF directory.
After you package the uncompiled classes, simply copy the JAR into the
wlserver\config\mydomain\applications directory. If necessary, WebLogic
Server automatically runs javac (or a compiler you specify) to compile the .java
files, and runs weblogic.ejbc to generate container classes. The compiled classes are
copied into a new JAR file in wlserver/config/mydomain/applications, and
deployed to the EJB container.
Should you ever modify an uncompiled ejbc .jar in the applications directory
(either by repackaging or copying over the JAR file), WebLogic Server automatically
recompiles and redeploys the JAR using the same steps.
8 Configuring Security in
EJBs
You can secure EJBs by restricting access to them. To restrict access to specified EJBs,
apply security constraints to them.
2. Add the following to the bottom of the session stanza for the bean, after
<transaction-type>:
<security-role-ref>
<role-name>admin</role-name>
<role-link<admin</role-link>
</security-role-ref>
<method-permission>
<role-name>admin</role-name>
<method>
<ejb-name>containerManaged</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
Note: Note that principals can be either users or groups in your security realm.
Note: If something concerning EJBs was fixed in a service pack, you will need to add
the service pack jar file to the front of the classpath in the build script in order
to take advantage of the fix.
6. Modify the Client.java to use user and credential when programming the
InitialContext.
Parameters are optional, but if any are supplied, they are interpreted in this
order:
a. url - URL such as "t3://localhost:7001" of Server user
The following sections provide a complete reference to the utilities and support files
supplied with WebLogic Server EJBs:
n ejbc (weblogic.ejbc)
n DDConverter (weblogic.ejb.utils.DDConverter)
n deploy (weblogic.deploy)
ejbc
Use the weblogic.ejbc command-line utility for generate and compiling EJB 2.0 and
1.1 container classes. If you compile JAR files for deployment into the EJB container,
you must use weblogic.ejbc to generate the container classes.
The WebLogic Server command line utility, weblogic.ejbc does the following:
n Places the EJB classes, interfaces, and XML deployment descriptor files in a
specified JAR file.
n Checks all EJB classes and interfaces for compliance with the EJB specification.
If you specify an output JAR file, ejbc places all generated files into the JAR file.
By default, ejbc uses javac as a compiler. For faster performance, specify a different
compiler (such as Symantec’s sj) using the -compiler flag.
Note: You may encounter problems deploying EJBs if there is a mismatched version
problem with weblogic.ejbc. When you start WebLogic Server it checks
which version of weblogic.ejbc was used to compile the container classes.
If the version of weblogic.ejbc used to compile the classes is different from
the version you are currently running the EJB will not deploy. To avoid this
problem, make sure that you do not put unnecessary classes in your class path.
ejbc Syntax
$ java weblogic.ejbc [options] <source jar file>
Note: If you output to a JAR file, the output JAR name must be different from the
input JAR name.
ejbc Arguments
The following table lists the weblogic.ejbc arguments:
Argument Description
<source jar Specifies the JAR file containing the compiled EJB classes,
file> interfaces, and XML deployment files.
ejbc Options
The following table lists the weblogic.ejbc command-line options:
Option Description
-dispatchPolicy Specifies a configured execute queue that the EJB should use
<queueName> for obtaining execute threads in WebLogic Server. See Using
Execute Queues to Control Thread Usage for more
information.
-idlDirectory <dir> Specifies the directory where ejbc creates IDL files. By
default, ejbc uses the current directory.
ejbc Examples
The following example uses the javac compiler against an input JAR file in
c:\wlserver\samples\examples\ejb\basic\containerManaged\build. The
output JAR file is placed in c:\wlserver\config\examples\applications.
$ java weblogic.ejbc -compiler javac
c:\wlserver\samples\examples\ejb\basic\containerManaged\build\std
_ejb_basic_containerManaged.jar
c:\wlserver\config\examples\ejb_basic_containerManaged.jar
The following example checks a JAR file for compliance with the EJB 1.1
specification and generates WebLogic Server container classes, but does not generate
RMI stubs:
$ java weblogic.ejbc -normi
c:\wlserver\samples\examples\ejb\basic\containerManaged\build\std
_ejb_basic_containerManaged.jar
DDConverter
The DDConverter is a command line utility that converts earlier versions EJB
deployment descriptors into EJB deployment descriptors that conform to the
WebLogic Server 6.x version. The WebLogic Server EJB container supports both the
EJB 1.1 and EJB 2.0 specifications including the EJB 1.1 and EJB 2.0 document type
definitions (DTD). Each WebLogic Server EJB deployment includes standard
deployment descriptors in the following files:
n ejb-jar.xml
This XML file contains the Sun Microsoft-specific EJB deployment descriptors.
n weblogic-ejb-jar-.xml
n Converting CMP and non-CMP beans from earlier version of the EJB
specification.
The following table lists the various conversion options for the DDconverter:
WLS 4.5 - WLS 6.x See Note 1 EJB CMP 1.0 - EJB CMP 1.1
See Note 2
WLS 4.5 - WLS 6.x EJB 1.1 - EJB 2.0 EJB CMP 1.0 - EJB CMP 2.0
WLS 5.x - WLS 6.x EJB 1.1 - EJB 2.0 See Note 3
Note 1: Converting non-CMP EJB 1.0 beans to non-CMP EJB 1.1 beans is not
necessary because the EJB 1.1 non-CMP deployment descriptors are the same
as the EJB 2.0 non-CMP deployment descriptors.
Note 2: Use the DDConverter command line option -EJBVer for converting EJB CMP
1.0 to EJB CMP 1.1. See “DDConverter Options” on page 9-7 for a description
of this option.
Note 3: Even thought WLS 5.x CMP 1.1 beans and WLS 6.x CMP 1.1 beans are
different, WLS 5.1 CMP 1.1 beans can run in WebLogic Server 6.x without
any changes to the source code.
You should always recompile the beans after you use the DDConverter. We
recommend that you use weblogic.ejbc and then deploy the new generated JAR file.
Recompiling the bean makes sure that the code is compliant with the EJB
Specifications and saves you time because you can skip the recompile process during
server startup.
n When converting WLS 4.5 EJB 1.0 beans to WLS 6.x EJB 1.1 beans, the input
to DDConverter is the WebLogic 4.5 deployment descriptor text. The output is a
JAR file that only includes the WebLogic 6.x deployment descriptors. Run
weblogic-ejbc to see if you need to make any additional changes to the source
code following the steps in “Using DDConverter to Convert EJBs” on page 9-6.
See the first row in the Conversion Options for the DDConverter Utility table.
n When converting WLS 4.5 EJB 1.1 beans to WLS 6.x EJB 2.0 beans, the input
to DDConverter is the WebLogic Server 4.5 deployment descriptor text. The
output is a JAR file that only includes the WebLogic 6.x deployment descriptors.
Run weblogic-ejbc to see if you need to make any additional changes to the
source code, follow the steps in “Using DDConverter to Convert EJBs” on page
9-6. See the second row in the Conversion Options for the DDConverter Utility
table.
n You can deploy WLS 5.x EJB 1.1 beans to WLS 6.x without any making
changes to the source code because WLS 6.x is backward compatible. WLS 6.x
detects, recompiles, and then deploys beans from previous versions of WLS.
However, we recommend that you use the DDConverter to upgrade the WLS 5.x
EJB 1.1 beans to WLS 6.x EJB 2.0 beans.
When converting WLS 5.x EJB 1.1 beans to WLS 6.x EJB 2.0 beans, the input
to DDConverter is the WebLogic 5.1 JAR file. This file contains the
deployment descriptor files and class files. The output goes to a JAR file that
includes the WebLogic 6.0 deployment descriptor files and all necessary class
files. See the third row in the Conversion Options for the DDConverter Utility
table.
You can convert non-CMP beans to EJB 2.0 beans with little or no changes to
the source code. To do this, run weblogic.ejbc on the output.jar file and then
deploy the generated JAR file. With CMP beans, you must make changes to the
source code using the steps in “Using DDConverter to Convert EJBs” on page
9-6.
1. Input the EJB’s deployment descriptor file into the DDConverter using the
command line format shown in “DDConverter Syntax” on page 9-7.
DDConverter Syntax
$ java weblogic.ejb20.utils.DDConverter [options] file1 [file2...]
DDConverter Arguments
DDConverter takes the argument file1 [file2...], where file is one of the
following:
DDConverter Options
The following table lists the DDConverter command-line options:
Option Description
-d destDir Specifies the destination directory for the output of
the JAR files.
This is a required option.
-c jar name Specifies a JAR file in which you combine all beans
in the source files.
-EJBVer output EJB Specifies the output EJB version number, such as 2.0
version or 1.1. The default is 2.0.
-log log file Specifies a file into which the log information can be
placed instead of the ddconverter.log.
DDConverter Examples
The following example converts a WLS 5.x EJB 1.1 bean into a WLS 6.x EJB 2.0
bean.
Where the Employee bean is a WLS 5.x EJB 1.1 JAR file.
deploy
The weblogic.deploy command-line utility is used to deploy an EJB-compliant JAR
file, the JAR’s EJBs to a running instance of WebLogic Server.
deploy Syntax
$ java weblogic.deploy [options] [list|deploy|undeploy|update]
password {name} {source}
deploy Arguments
The following table lists the weblogic.deploy command line arguments:
Argument Description
deploy Options
The following table lists the weblogic.deploy command line options:
Option Description
10 weblogic-ejb-jar.xml
Document Type
Definitions
The following sections describe the EJB 5.1 and EJB 6.0 deployment descriptor
elements found in the weblogic-ejb-jar.xml file, the weblogic-specific XML
document type definitions (DTD) file. Use these definitions to create the
WebLogic-specific weblogic-ejb-jar.xml file that is part of your EJB deployment.
Note: Use the 6.0 deployment descriptors with the 6.x version of WebLogic Server.
n weblogic-ejb-jar.xml
n weblogic-cmp-rdbms-jar.xml
You package these three XML files with the EJB and other classes into a deployable
EJB component, usually a JAR file, called ejb.jar.
The correct text for the PUBLIC elements for the WebLogic Server-specific
weblogic-ejb-jar.xml file are as follows.
The correct text for the PUBLIC elements for the Sun Microsystem-specific
ejb-jar.xml file are as follows.
XML files with incorrect header information may yield error messages similar to the
following, when used with a utility that parses the XML (such as ejbc):
SAXException: This document may not have the identifier ‘identifier_name’
identifier_name generally includes the invalid text from the PUBLIC element.
uses the DTD locations that were installed along with the server. However, the
DOCTYPE header information must include a valid URL syntax in order to avoid parser
errors.
Note: Most browsers do not display the contents of files having the .dtd extension.
To view the DTD file contents in your browser, save the links as text files and
view them with a text editor.
weblogic-ejb-jar.xml
The following links provide the new public DTD locations for the
weblogic-ejb-jar.xml deployment files used with the WebLogic Server:
ejb-jar.xml
The following links provide the public DTD locations for the ejb-jar.xml
deployment files used with WebLogic Server:
Note: Refer to the appropriate JavaSoft EJB specification for a description of the
ejb-jar.xml deployment descriptors.
The top level elements in the WebLogic Server 6.0 weblogic-ejb-jar.xml are as
follows:
n description
n weblogic-version
n weblogic-enterprise-bean
l ejb-name
l entity-descriptor | stateless-session-descriptor |
stateful-session-descriptor | message-driven-descriptor
l transaction-descriptor
l reference-descriptor
l enable-call-by-reference
l jndi-name
n security-role-assignment
n transaction-isolation
allow-concurrent-calls
Range of values: true | false
Requirements: Requires the server to throw a RemoteException when a stateful session bean
instance is currently handling a method call and another (concurrent) method call arrives
on the server.
Function
The allow-concurrent-calls element specifies whether a stateful session bean
instance allows concurrent method calls. By default, allows-concurrent-calls is
false. However, when this value is set to true, the EJB container blocks the
concurrent method call and allows it to proceed when the previous call has completed.
Example
See “stateful-session-descriptor” on page 10-73.
cache-type
Range of values: NRU | LRU
Requirements:
Function
The cache-type element specifies the order in which EJBs are reomoved from the
cache. The values are:
Example
The following example shows the structure of the cache-type element.
<stateful-session-cache>
<cache-type>NRU</cache-type>
</stateful-session-cache>
connection-factory-jndi-name
Range of values: valid name
Requirements: Requires the server to throw a RemoteException when a stateful session bean
instance is currently handling a method call and another (concurrent) method call arrives
on the server.
Function
The connection-factory-jndi-name element specifies the JNDI name of the JMS
ConnectionFactory that the MessageDriven Bean should look up to create its queues
and topics. If this element is not specified, the default is the
weblogic.jms.MessageDrivenBeanConnectionFactory in config.xml.
Example
The following example shows the structure of the connection-factory-jndi-name
element:
<message-driven-descriptor>
<connection-factory-jndi-name>weblogic.jms.MessageDrivenBean
ConnectionFactory</connection-factory-jndi-name>
</message-driven-descriptor>
concurrency-strategy
Range of values: Exclusive | Database | ReadOnly
Function
The concurrency-strategy element specifies how the container should manage
concurrent access to an entity bean. Set this element to one of three values:
n Database causes WebLogic Server to defer locking requests for an entity EJB to
the underlying datastore. With the Database concurrency strategy, WebLogic
Server does not cache the intermediate results of entity EJBs involved in a
transaction. This is the current default option.
See“Locking Services for Entity EJBs” on page 4-34 for more information on the
Exclusive and Database locking behaviors. See“Read-Only Multicast Invalidation”
on page 4-14 for more information about read-only entity EJBs.
Example
The following entry identifies the AccountBean class as a read-only entity EJB:
<weblogic-enterprise-bean>
<ejb-name>AccountBean</ejb-name>
<entity-descriptor>
<entity-cache>
<concurrency-strategy>ReadOnly</concurrency-strategy>
</entity-cache>
</entity-descriptor>
</weblogic-enterprise-bean>
db-is-shared
Range of values: true | false
Function
The db-is-shared element applies only to entity beans. When it is set to true,
WebLogic Server assumes that EJB data can be modified between transactions and
reloads the data at the beginning of each transaction. When set to false, WebLogic
Server assumes that it has exclusive access to the EJB data in the persistent store. See
“Using db-is-shared to Limit Calls to ejbLoad()” on page 4-10 for more information.
Example
See “persistence” on page 10-53.
delay-updates-until-end-of-tx
Range of values: true | false
Function
Set the delay-updates-until-end-of-tx element to true (the default) to update
the persistent store of all beans in a transaction at the completion of the transaction.
This setting generally improves performance by avoiding unnecessary updates.
However, it does not preserve the ordering of database updates within a database
transaction.
Example
The following example shows a delay-updates-until-end-of-tx stanza.
<entity-descriptor>
<persistence>
<delay-updates-until-end-of-tx>false</delay-updates-until-end-of-
tx>
</persistence>
</entity-descriptor>
description
Range of values: n/a
Requirements: n/a
Function
The description element is used to provide text that describes the parent element.
Example
The following examples specifies the description element.
destination-jndi-name
Range of values: Valid JNDI name
Function
The destination-jndi-name element specifies the JNDI name used to associate a
message-driven bean with an actual JMS Queue or Topic deployed in the in WebLogic
Server JNDI tree.
Example
See “message-driven-descriptor” on page 10-46.
ejb-name
Range of values: Name of an EJB defined in ejb-jar.xml
Requirements: Required element in method stanza. The name must conform to the lexical rules for an
NMTOKEN.
Function
ejb-name specifies the name of an EJB to which WebLogic Server applies isolation
level properties. This name is assigned by the ejb-jar file’s deployment descriptor.
The name must be unique among the names of the enterprise beans in the same
ejb.jar file. The enterprise bean code does not depend on the name; therefore the
name can be changed during the application-assembly process without breaking the
enterprise bean’s function. There is no built-in relationship between the ejb-name in
the deployment descriptor and the JNDI name that the deployer will assign to the
enterprise bean’s home.
Example
See “method” on page 10-47.
ejb-reference-description
Range of values: n/a (XML stanza)
Function
The ejb-reference-description element maps the JNDI name in the WebLogic
Server of an EJB that is referenced by the bean in the ejb-reference element.
Example
The ejb-reference-description stanza is shown here:
<ejb-reference-description>
<ejb-ref-name>AdminBean</ejb-ref-name>
<jndi-name>payroll.AdminBean</jndi-name>
</ejb-reference-description>
ejb-ref-name
Range of values: n/a
Function
The ejb-ref-name element specifies a resource reference name. This element is the
reference that the EJB provider places within the ejb-jar.xml deployment file.
Example
The ejb-ref-name stanza is shown here:
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>AdminBean</ejb-ref-name>
<jndi-name>payroll.AdminBean</jndi-name>
</ejb-reference-description>
</reference-descriptor>
ejb-local-reference-description
Range of values: n/a (XML stanza)
Function
The ejb-local-reference-description element maps the JNDI name of an EJB
in the WebLogic Server that is referenced by the bean in the ejb-local ref element.
Example
The folllowing example shows the ejb-local-reference-description element.
<ejb-local-reference-description>
<ejb-ref-name>AdminBean</ejb-ref-name>
<jndi-name>payroll.AdminBean</jndi-name>
</ejb-local-reference-description>
enable-call-by-reference
Range of values: true | false
Function
By default, EJB methods called from within the same server pass arguments by
reference. This increases the performance of method invocation because parameters
are not copied.
Example
The following example enables pass-by-value for EJB methods:
<weblogic-enterprise-bean>
<ejb-name>AccountBean</ejb-name>
...
<enable-call-by-reference>false</enable-call-by-reference>
</weblogic-enterprise-bean>
entity-cache
Range of values: n/a (XML stanza)
Requirements: The entity-cache stanza is optional, and is valid only for entity EJBs.
Function
The entity-cache element defines the following options used to cache entity EJB
instances within WebLogic Server:
n max-beans-in-cache
n idle-timeout-seconds
n read-timeout-seconds
n concurrency-strategy
See“EJB Life Cycle in WebLogic Server” on page 4-2 for a general discussion of the
caching services available in WebLogic Server.
Example
<entity-descriptor>
<entity-cache>
<max-beans-in-cache>...</max-beans-in-cache>
<idle-timeout-seconds>...</idle-timeout-seconds>
<read-timeout-seconds>...<read-timeout-seconds>
<concurrency-strategy>...</concurrency-strategy>
</entity-cache>
<lifecycle>...</lifecycle>
<persistence>...</persistence>
<entity-clustering>...</entity-clustering>
</entity-descriptor>
entity-clustering
Range of values: n/a (XML stanza)
Function
The entity-clustering element uses the following options to specify how an entity
bean will be replicated in a WebLogic cluster:
n home-is-clusterable
n home-load-algorithm
n home call-router-class-name
Example
The following excerpt shows the structure of a entity-clustering stanza:
<entity-clustering>
<home-is-clusterable>true</home-is-clusterable>
<home-load-algorithm>random</home-load-algorithm>
<home-call-router-class-name>beanRouter</home-call-router-class-n
ame>
</entity-clustering>
entity-descriptor
Range of values: n/a (XML stanza)
Requirements: One entity-descriptor stanza is required for each entity EJB in the .jar.
Function
The entity-descriptor element specifies the following deployment parameters
that are applicable to an entity bean:
n pool
n entity-cache
n lifecycle
n persistence
n entity-clustering
Example
The following example shows the structure of the entity-descriptor stanza:
<entity-descriptor>
<entity-cache>...</entity-cache>
<lifecycle>...</lifecycle>
<persistence>...</persistence>
<entity-clustering>...</entity-clustering>
</entity-descriptor>
finders-load-bean
Range of values: true | false
Function
The finders-load-bean element determines whether WebLogic Server loads the
EJB into the cache after a call to a finder method returns a reference to the bean. If you
set this element to true, WebLogic Server immediately loads the bean into the cache
if a reference to a bean is returned by the finder. If you set this element to false,
WebLogic Server does not load automatically load the bean into the cache until the
first method invocation; this behavior is consistent with the EJB 1.1 specification.
Example
The following entry specifies that EJBs are loaded into the WebLogic Server cache
automatically when a finder method returns a reference to the bean:
<entity-descriptor>
<persistence>
<finders-load-bean>true</finders-load-bean>
</persistence>
</entity-descriptor>
home-call-router-class-name
Range of values: Valid router class name
Requirements: Optional element. Valid only for entity EJBs, stateful session EJBs, and stateless session
EJBs in a cluster.
Function
home-call-router-class-name specifies the name of a custom class to use for
routing bean method calls. This class must implement
weblogic.rmi.extensions.CallRouter(). If specified, an instance of this class is
called before each method call. The router class has the opportunity to choose a server
to route to based on the method parameters. The class returns either a server name or
null, which indicates that the current load algorithm should select the server.
Example
See “entity-clustering” on page 10-24 and “stateful-session-clustering” on page 10-72.
home-is-clusterable
Range of values: true | false
Requirements: Optional element. Valid for entity EJBs, stateless EJBs, and stateful session EJBs in a
cluster.
Function
Use home-is-clusterable to specify whether the home interface of an entity,
stateless session, or stateful session bean is clustered.
When home-is-clusterable is true for an EJB deployed to a cluster, each server
instance binds the bean’s home interface to its cluster JNDI tree under the same name.
When a client requests the bean’s home from the cluster, the server instance that does
the look-up returns a EJBHome stub that has a reference to the home on each server.
When the client issues a create() or find() call, the stub routes selects a server from
the replica list in accordance with the load balancing algorithm, and routes the call to
the home interface on that server. The selected home interface receives the call, and
creates a bean instance on that server instance and executes the call, creating an
instance of the bean.
Example
See “entity-clustering” on page 10-24.
home-load-algorithm
Range of values: round-robin | random | weight-based
Requirements: Optional element. Valid only for entity EJBs and stateful session EJBs in a cluster.
Function
home-load-algorithm specifies the algorithm to use for load balancing between
replicas of the EJB home. If this property is not defined, WebLogic Server uses the
algorithm specified by the server property,
weblogic.cluster.defaultLoadAlgorithm.
n random: Replicas of the EJB home are deployed randomly among the servers
hosting the bean.
Example
See “entity-clustering” on page 10-24 and “stateful-session-clustering” on page 10-72.
idle-timeout-seconds
Range of values: 1 to maxSeconds, where maxSeconds is the maximum value of an int.
Function
idle-timeout-seconds defines the maximum length of time a stateful EJB should
remain in the cache. After this time has elapsed, WebLogic Server removes the bean
instance if the number of beans in cache approaches the limit of
max-beans-in-cache. The removed bean instances are passivated. See “EJB Life
Cycle in WebLogic Server” on page 4-2 for more information.
Example
The following entry indicates that the stateful session EJB, AccountBean, should
become eligible for removal if max-beans-in-cache is reached and the bean has
been in cache for 20 minutes:
<weblogic-enterprise-bean>
<ejb-name>AccountBean</ejb-name>
<stateful-session-descriptor>
<stateful_session-cache>
<max-beans-in-cache>200</max-beans-in-cache>
<idle-timeout-seconds>1200</idle-timeout-seconds>
</stateful-session-cache>
</stateful-session-descriptor>
</weblogic-enterprise-bean>
initial-beans-in-free-pool
Range of values: 0 to maxBeans
Default value: 0
Requirements: Optional element. Valid for stateless session, entity, and message-driven EJBs.
Function
If you specify a value for initial-beans-in-free-pool, you set the initial size of
the pool. WebLogic Server populates the free pool with the specified number of bean
instances for every bean class at startup. Populating the free pool in this way improves
initial response time for the EJB, because initial requests for the bean can be satisfied
without generating a new instance.
Example
See “pool” on page 10-58.
initial-context-factory
Range of values: true | false
Requirements: Requires the server to throw a RemoteException when a stateful session bean
instance is currently handling a method call and another (concurrent) method call arrives
on the server.
Function
The initial-context-factory element specifies the initial contextFactory that the
container will use to create its connection factories. If initial-context-factory is not
specified, the default will be weblogic.jndi.WLInitialContextFactory.
Example
The following example specifies the initial-context-factory element.
<message-driven-descriptor>
<initial-context-factory>weblogic.jndi.WLInitialContextFactory
</initial-context-factory>
</message-driven-descriptor>
invalidation-target
Range of values:
Default value:
Requirements: The target ejb-name must be a Read-Only entity EJB and this element can only be
specified for an EJB 2.0 container-managed persistence entity EJB.
Function
The invalidation-target element specifies a Read-Only entity EJB that should be
invalidated when this container-managed persistence entity EJB has been modified.
Example
The following entry specifies that the EJB named StockReaderEJB should be
invalidated when the EJB has been modified.
<invalidation-target>
<ejb-name>StockReaderEJB</ejb-name>
</invalidation-target>
is-modified-method-name
Range of values: Valid entity EJB method name
Function
is-modified-method-name specifies a method that WebLogic Server calls when the
EJB is stored. The specified method must return a boolean value. If no method is
specified, WebLogic Server always assumes that the EJB has been modified and
always saves it.
Providing a method and setting it as appropriate can improve performance for EJB
1.1-compliant beans, and for beans that use bean-managed persistence. However, any
errors in the method’s return value can cause data inconsistency problems. See“Using
is-modified-method-name to Limit Calls to ejbStore() (EJB 1.1 Only)” on page 4-11
for more information.
Note: isModified() is no longer required for 2.0 CMP entity EJBs based on the
EJB 2.0 specification However, it still applies to BMP and 1.1 CMP EJBs.
When you deploy EJB 2.0 entity beans with container-managed persistence,
WebLogic Server automatically detects which EJB fields have been modified,
and writes only those fields to the underlying datastore.
Example
The following entry specifies that the EJB method named semidivine will notify
WebLogic Server when the EJB has been modified:
<entity-descriptor>
<persistence>
<is-modified-method-name>semidivine</is-modified-method-name>
</persistence>
</entity-descriptor>
isolation-level
Range of values: Serializable | ReadCommitted | ReadUncommitted |
RepeatableRead
Function
isolation-level specifies the isolation level for all of the EJB’s database
operations. The following are possible values for isolation-level:
Refer to your database documentation for more information on the implications and
support for different isolation levels.
Example
See “transaction-isolation” on page 10-82.
jms-client-id
Range of values: N/A
Function
The jms-client-id element specifies the client ID associated with the
message-driven bean. This ID is necessary for durable subscriptions to JMS topics.
If the associated client ID does not have a client ID or if you are using the default
connection factory, the message-driven bean uses the jms-client-id value as its
client ID.
Example
The following example specifies the use of the jms-client-id element.
<jms-client-id>MyClientID</jms-client-id>
jms-polling-interval-seconds
Range of values: none
Requirements: .none
Function
The jms-polling-interval-seconds element determines the number of seconds
between each attempt by WebLogic Server to reconnect to the JMS destination.
Refer to your database documentation for more information on the implications and
support for different isolation levels.
Example
The following example specifies the use of the jms-pollig-interval-seconds
element.
<jms-polling-interval-seconds>5</jms-polling-interval-seconds>
jndi-name
Range of values: Valid JNDI name
Function
jndi-name specifies the JNDI name of an actual EJB, resource, or reference available
in WebLogic Server.
Example
See “resource-description” on page 10-66 and “ejb-reference-description” on page
10-19.
local-jndi-name
Range of values: Valid JNDI name
Function
The local-jndi-name element specifies a jndi-name for a bean’s local home. If a
bean has both a remote and a local home, then it must have two JNDI names; one for
each home.
Example
The following example shows the specifies the local-jndi-name element.
<local-jndi-name>weblogic.jndi.WLInitialContext
</local-jndi-name>
lifecycle
Range of values: n/a (XML stanza)
Function
The lifecycle element defines options that affect the lifecycle of stateful and entity
EJB instances within WebLogic Server. Currently, the lifecycle element includes
only one element: passivation-strategy.
Example
The following example shows the specifies the lifecycle element.
<entity-descriptor>
<lifecycle>
<passivation-strategy>...</passivation-strategy>
</lifecycle>
</entity-descriptor>
max-beans-in-cache
Range of values: 1 to maxBeans
Function
The max-beans-in-cache element specifies the maximum number of objects of this
class that are allowed in memory. When max-bean-in-cache is reached, WebLogic
Server passivates some EJBs that have not been recently used by a client.
max-beans-in-cache also affects when EJBs are removed from the WebLogic
Server cache, as described in“Locking Services for Entity EJBs” on page 4-34.
Example
The following entry enables WebLogic Server to cache a maximum of 200 instances
of the AccountBean class:
<weblogic-enterprise-bean>
<ejb-name>AccountBean</ejb-name>
<entity-descriptor>
<entity-cache>
<max-beans-in-cache>200</max-beans-in-cache>
</entity-cache>
</entity-descriptor>
</weblogic-enterprise-bean>
max-beans-in-free-pool
Range of values: 0 to maxBeans
Function
WebLogic Server maintains a free pool of EJBs for every stateless session bean and
message driven bean class. The max-beans-in-free-pool element defines the size
of this pool. By default, max-beans-in-free-pool has no limit; the maximum
number of beans in the free pool is limited only by the available memory. See
“Differences Between Message-Driven Beans and Stateless Session EJBs” on page
3-3 for more information.
Example
See “pool” on page 10-58.
message-driven-descriptor
Range of values: n/a (XML stanza)
Requirements:
Function
The message-driven-descriptor element associates a message-driven bean with a
JMS destination in WebLogic Server. This element specifies the following
deployment parameters:
n pool
n destination-jndi-name
n initial-context-factory
n provider-url
n connection-factory-jndi-name
Example
The following example shows the structure of the message-driven-descriptor
stanza:
<message-driven-descriptor>
<destination-jndi-name>...</destination-jndi-name>
</message-driven-descriptor>
method
Range of values: n/a (XML stanza)
Requirements: Optional element. You can specify more than one method stanza to configure multiple
EJB methods.
Function
The method element defines a method or set of methods for an enterprise bean’s home
or remote interface.
Example
The method stanza can contain the elements shown here:
<method>
<description>...</description>
<ejb-name>...</ejb-name>
<method-intf>...</method-intf>
<method-name>...</method-name>
<method-params>...</method-params>
</method>
method-intf
Range of values: Home | Remote
Function
method-intf specifies the EJB interface to which WebLogic Server applies isolation
level properties. Use this element only if you need to differentiate between methods
having the same signature in the EJB’s home and remote interface.
Example
See “method” on page 10-47.
method-name
Range of values: Name of an EJB defined in ejb-jar.xml | *
Function
method-name specifies the name of an individual EJB method to which WebLogic
Server applies isolation level properties. Use the asterisk (*) to specify all methods in
the EJB’s home and remote interfaces.
Example
See “method” on page 10-47.
method-param
Range of values: Fully qualified Java type of a method parameter
Function
The method-param element specifies the fully qualified Java type name of a method
parameter.
Example
See “method-params” on page 10-51.
method-params
Range of values: n/a (XML stanza)
Function
The method-params stanza contains one or more elements that define the Java type
name of each of the method’s parameters.
Example
The method-params stanza contains one or more method-param elements, as shown
here:
<method-params>
<method-param>java.lang.String</method-param>
...
</method-params>
passivation-strategy
Range of values: default | transaction
Function
The passivation-strategy element determines whether or not WebLogic Server
maintains the intermediate state of entity EJBs in its cache. See “Locking Services for
Entity EJBs” on page 4-34 for more information.
Example
The following entry reverts to WebLogic Server locking and caching behavior:
<entity-descriptor>
<lifecycle>
<passivation-strategy>default</passivation-strategy>
</lifecycle>
</entity-descriptor>
persistence
Range of values: n/a (XML stanza)
Requirements: Required only for entity EJBs that use container-managed persistence services.
Function
The persistence element defines the following options that determine the
persistence type, transaction commit behavior, and ejbLoad() and ejbStore()
behavior for entity EJBs in WebLogic Server:
n is-modified-method-name
n delay-updates-until-end-of-tx
n finders-load-bean
n persistence-type
n db-is-shared
n persistence-use
Example
The following example specifies the persistence element.
<entity-descriptor>
<persistence>
<is-modified-method-name>...</is-modified-method-name>
<delay-updates-until-end-of-tx>...</delay-updates-until-end-of-tx
>
<finders-load-beand>...</finders-load-bean>
<persistence-type>...</persistence-type>
<db-is-shared>false</db-is-shared>
<persistence-use>...</persistence-use>
</persistence>
</entity-descriptor>
persistence-type
Range of values: n/a (XML stanza)
Requirements: Required only for entity EJBs that use container-managed persistence services.
Function
The persistence-type element defines a persistence service that the entity EJB can
use. You can define multiple persistence-type stanzas in
weblogic-ejb-jar.xml for testing your EJB with multiple persistence services.
Only the persistence type defined in persistence-use is actually used during
deployment.
n type-identifier
n type-version
n type-storage
Example
The following excerpt shows a sample persistence-type stanza:
<persistence>
<persistence-type>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>5.1.0</type-version>
<type-storage>META-INF\weblogic-cmp-rdbms-jar.xml</type-storage>
</persistence-type>
</persistence>
persistence-use
Range of values: n/a (XML stanza)
Requirements: Required only for entity EJBs that use container-managed persistence services.
Function
The persistence-use element is similar to persistence-type, but it defines the
persistence service actually used during deployment. persistence-use uses the
type-identifier and type-version elements defined in a persistence-type to identify
the service.
Example
To deploy an EJB using the WebLogic Server RDBMS-based persistence service
defined in persistence-type, use the following persistence-use stanza:
<persistence-use>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>5.1.0</type-version>
</persistence-use>
persistent-store-dir
Range of values: Fully qualified filesystem path
Function
The persistent-store-dir element specifies a file system directory where
WebLogic Server stores the state of passivated stateful session bean instances.
Example
See “stateful-session-descriptor” on page 10-73.
pool
Range of values: n/a (XML stanza)
Function
The pool element configures the behavior of the WebLogic Server free pool for
stateless session and message driven EJBs. The options are:
n max-beans-in-free-pool
n initial-beans-in-free-pool
Example
The pool stanza can contain the elements shown here:
<stateless-session-descriptor>
<pool>
<max-beans-in-free-pool>500</max-beans-in-free-pool>
<initial-beans-in-free-pool>250</initial-beans-in-free-pool>
</pool>
</stateless-session-descriptor>
principal-name
Range of values: valid WebLogic Server principal name
Function
principal-name specifies the name of an actual WebLogic Server principal to apply
to the specified role-name.
Example
See “security-role-assignment” on page 10-70.
provider-url
Range of values: valid name
Function
The provider-url element specifies the URL provider to be used by the
InitialContext. Typically, this is the host : port and used in conjunction with
initial-context-factory and connection-factory-jndi-name.
Example
The following example specifies the provider-url element.
<message-driven-descriptor>
<provider-url>WeblogicURL:Port</provider-url>
</message-driven-descriptor>
read-timeout-seconds
Range of values: 0 to maxSeconds, where maxSeconds is the maximum value of an int.
Function
The read-timeout-seconds element specifies the number of seconds between
ejbLoad() calls on a Read-Only entity bean. By default, read-timeout-seconds
is set to 600, and WebLogic Server calls ejbLoad() only when the bean is brought
into the cache.
Example
The following entry causes WebLogic Server to call ejbLoad() for instances of the
AccountBean class only when the instance is first brought into the cache:
<weblogic-enterprise-bean>
<ejb-name>AccountBean</ejb-name>
<entity-descriptor>
<entity-cache>
<read-timeout-seconds>0</read-timeout-seconds>
</entity-cache>
</entity-descriptor>
</weblogic-enterprise-bean>
reference-descriptor
Range of values: n/a (XML stanza)
Function
The reference-descriptor element maps references in the ejb-jar.xml file to
the JNDI names of actual resource factories and EJBs available in WebLogic Server.
Example
The reference-descriptor stanza contains one or more additional stanzas to define
resource factory references and EJB references. The following shows the organization
of these elements:
<reference-descriptor>
<resource-description>
...
</resource-description>
<ejb-reference-description>
...
</ejb-reference-description>
</reference-descriptor>
relationship-description
This element is no longer supported in WebLogic Server.
replication-type
Range of values: InMemory | None
Requirements: Optional element. Valid only for stateful session EJBs in a cluster.
Function
The replication-type element determines whether WebLogic Server replicates the
state of stateful session EJBs across WebLogic Server instances in a cluster. If you
select InMemory, the state of the EJB is replicated. If you select None, the state is not
replicated.
See “In-Memory Replication for Stateful Session EJBs” on page 4-22 for more
information.
Example
See “stateful-session-clustering” on page 10-72.
res-env-ref-name
Range of values: A valid resource environment reference name from the ejb-jar.xml file
Requirements: n/a
Function
The res-env-ref-name element specifies the name of a resource environment
reference.
Example
See “resource-description” on page 10-66.
res-ref-name
Range of values: A valid resource reference name from the ejb-jar.xml file
Function
The res-ref-name element specifies the name of a resourcefactory reference.
This is the reference that the EJB provider places within the ejb-jar.xml deployment
file.
Example
See “resource-description” on page 10-66.
resource-description
Range of values: n/a (XML stanza)
Function
The resource-description element maps a resource reference defined in
ejb-jar.xml to the JNDI name of an actual resource available in WebLogic Server.
Example
The resource-description stanza can contain additional elements as shown here:
<reference-descriptor>
<resource-description>
<res-ref-name>. . .</res-ref-name>
<jndi-name>...</jndi-name>
</resource-description>
<ejb-reference-description>
<ejb-ref-name>. . .</ejb-ref-name>
<jndi-name>. . .</jndi-name>
</ejb-reference-description>
</reference-descriptor>
resource-env-description
Range of values: n/a (XML stanza)
Function
The resource-env-description element maps a resource environment reference
defined in ejb-jar.xml to the JNDI name of an actual resource available in
WebLogic Server.
Example
The resource-env-description stanza can contain additional elements as shown
here:
<reference-descriptor>
<resource-env-description>
<res-env-ref-name>. . .</res-env-ref-name>
<jndi-name>...</jndi-name>
<reference-env-description>
</reference-descriptor>
role-name
Range of values: An EJB role name defined in ejb-jar.xml
Function
The role-name element identifies an application role name that the EJB provider
placed in the ejb-jar.xml deployment file. Subsequent principal-name elements
in the stanza map WebLogic Server principals to the specified role-name.
Example
See “security-role-assignment” on page 10-70.
run-as-identity-principal
Note: This element has been deprecated. It is here for backward compatibility only.
Range of values: Principal that will be used as the identity as defined in ejb-jar.xml
Function
The run-as-identity-principal element specifies the principal to be used as the
identity for beans that have a security-identity.run-as-specified-identity
set in the ejb-jar.xml.
The principal named in this element must be one of the principals mapped to the
run-as-specified--identity role.
Example
The run-as-identity-principal stanza can contain additional elements as shown
here:
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<run-as-identity-principal>Fred</run-as-identity-principal>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
security-role-assignment
Range of values: n/a (XML stanza)
Function
The security-role-assignment stanza maps application roles in the ejb-jar.xml
file to the names of security principals available in WebLogic Server.
Example
The security-role-assignment stanza can contain one or more of the following
elements:
<security-role-assignment>
<role-name>PayrollAdmin</role-name>
<principal-name>Tanya</principal-name>
<principal-name>system</principal-name>
...
</security-role-assignment>
stateful-session-cache
Range of values: n/a (XML stanza)
Requirements: The stateful-session-cache stanza is optional, and is valid only for stateful
session EJBs.
Function
The stateful-session-cache element defines the following options used to cache
stateful session EJB instances within WebLogic Server.
n max-beans-in-cache
n idle-timeout-seconds
n cache-type
See“EJB Life Cycle in WebLogic Server” on page 4-2 for a general discussion of the
caching services available in WebLogic Server.
Example
The following example shows how to specify the stateful-session-cache element
<stateful-session-cache>
<max-beans-in-cache>...</max-beans-in-cache>
<idle-timeout-seconds>...</idle-timeout-seconds>
<cache-type>...<cache-type>
</stateful-session-cache>
stateful-session-clustering
Range of values: n/a (XML stanza)
Requirements: Optional element. Valid only for stateful session EJBs in a cluster.
Function
The stateful-session-clustering stanza element specifies the following options
that determine how WebLogic Server replicates stateful session EJB instances in a
cluster:
n home-is-clusterable
n home-load-algorithm
n home-call-router-class-name
n replication-type
Example
The following excerpt shows the structure of a entity-clustering stanza:
<stateful-session-clustering>
<home-is-clusterable>true</home-is-clusterable>
<home-load-algorithm>random</home-load-algorithm>
<home-call-router-class-name>beanRouter</home-call-router-class-n
ame>
<replication-type>InMemory</replication-type>
</stateful-session-clustering>
stateful-session-descriptor
Range of values: n/a (XML stanza)
Function
The stateful-session-descriptor element specifies the following deployment
parameters that are applicable for stateful session EJBs in WebLogic Server:
n stateful-session-cache
n lifecycle
n persistent-store-dir
n stateful-session-clustering
n allow-concurrent-calls
Example
The following example shows the structure of the stateful-session-descriptor
stanza:
<stateful-session-descriptor>
<stateful-session-cache>...</stateful-session-cache>
<lifecycle>...</lifecycle>
<persistence>...</persistence>
<allow-concurrent-calls>...</allow-concurrent-calls>
<persistent-store-dir>/weblogic/myserver</persistent-store-dir>
<stateful-session-clustering>...</stateful-session-clustering>
</stateful-session-descriptor>
stateless-bean-call-router-class-name
Range of values: Valid router class name
Requirements: Optional element. Valid only for stateless session EJBs in a cluster.
Function
The stateless-bean-call-router-class-name element specifies the name of a
custom class to use for routing bean method calls. This class must implement
weblogic.rmi.extensions.CallRouter(). If specified, an instance of this class is
called before each method call. The router class has the opportunity to choose a server
to route to based on the method parameters. The class returns either a server name or
null, which indicates that the current load algorithm should select the server.
Example
See “stateless-clustering” on page 10-79.
stateless-bean-is-clusterable
Range of values: true | false
Requirements: Optional element. Valid only for stateless session EJBs in a cluster.
Function
Use stateless-bean-is-clusterable to specify whether a stateless session
bean’s EJBObject interface is clustered. Clustered EJBObjects support load
balancing and failover.
Example
See “stateless-clustering” on page 10-79.
stateless-bean-load-algorithm
Range of values: round-robin | random | weight-based
Requirements: Optional element. Valid only for stateless session EJBs in a cluster.
Function
stateless-bean-load-algorithm specifies the algorithm to use for load balancing
between replicas of the EJB home. If this property is not defined, WebLogic Server
uses the algorithm specified by the server property,
weblogic.cluster.defaultLoadAlgorithm.
n random: Replicas of the EJB home are deployed randomly among the servers
hosting the bean.
Example
See “stateless-clustering” on page 10-79.
stateless-bean-methods-are-idempotent
Range of values: true | false
Requirements: Optional element. Valid only for stateless session EJBs in a cluster.
Function
You can set this element to either true or false. Set
stateless-bean-methods-are-idempotent to “true” only if the bean is written
such that repeated calls to the same method with the same arguments has exactly the
same effect as a single call. This allows the failover handler to retry a failed call
without knowing whether the call actually completed on the failed server. Setting this
property to true makes it possible for the bean stub to recover automatically from any
failure as long as another server hosting the bean can be reached.
Example
See “stateless-clustering” on page 10-79.
stateless-clustering
Range of values: n/a (XML stanza)
Requirements: Optional element. Valid only for stateless session EJBs in a cluster.
Function
The stateless-clustering element specifies the following options that determine
how WebLogic Server replicates stateless session EJB instances in a cluster:
n home-is-clusterable
n stateless-bean-is-clusterable
n stateless-bean-load-algorithm
n stateless-bean-call-router-class-name
n stateless-bean-methods-are-idempotent
Example
The following excerpt shows the structure of a stateless-clustering stanza:
<stateless-clustering>
<stateless-bean-is-clusterable>true</stateless-bean-is-clusterabl
e>
<stateless-bean-load-algorithm>random</stateless-bean-load-algori
thm>
<stateless-bean-call-router-class-name>beanRouter</stateless-bean
-call-router-class-name>
<stateless-bean-methods-are-idempotent>true</stateless-bean-metho
ds-are-idempotent>
</stateless-clustering>
stateless-session-descriptor
Range of values: n/a (XML stanza)
Function
The stateless-session-descriptor element defines deployment parameters,
such as caching, clustering, and persistence for stateless session EJBs in WebLogic
Server.
Example
The following example shows the structure of the stateless-session-descriptor
stanza:
<stateless-session-descriptor>
<pool>...</pool>
<stateless-clustering>...</stateless-clustering>
</stateless-session-descriptor>
transaction-descriptor
Range of values: n/a (XML stanza)
Function
The transaction-descriptor element specifies options that define transaction
behavior in WebLogic Server. Currently, this stanza includes only one element:
trans-timeout-seconds.
Example
The following example shows the structure of the transaction-descriptor stanza:
<transaction-descriptor>
<trans-timeout-seconds>20</trans-timeout-seconds>
<transaction-descriptor>
transaction-isolation
Range of values: n/a (XML stanza)
Function
The transaction-isolation element defines method-level transaction isolation
settings for an EJB.
Example
The transaction-isolation stanza can contain the elements shown here:
<transaction-isolation>
<isolation-level>Serializable</isolation-level>
<method>
<description>...</description>
<ejb-name>...</ejb-name>
<method-intf>...</method-intf>
<method-name>...</method-name>
<method-params>...</method-params>
</method>
</transaction-isolation>
trans-timeout-seconds
Range of values: 0 to max
Default value: 30
Function
The trans-timeout-seconds element specifies the maximum duration for an EJB’s
container-initiated transactions. If a transaction lasts longer than
trans-timeout-seconds, WebLogic Server rolls back the transaction.
Example
See “transaction-descriptor” on page 10-81.
type-identifier
Range of values: Valid string
Requirements: Required only for entity EJBs that use container-managed persistence services.
Function
The type-identifier element contains text that identifies an entity EJB persistence
type. WebLogic Server RDBMS-based persistence uses the identifier,
WebLogic_CMP_RDBMS. If you use a different persistence vendor, consult the vendor’s
documentation for information on the correct type-identifier.
Example
See “persistence-type” on page 10-54 for an example that shows the complete
persistence-type definition for WebLogic Server RDBMS-based persistence.
type-storage
Range of values: Valid string
Requirements: Required only for entity EJBs that use container-managed persistence services.
Function
The type-storage element defines the full path of the file that stores data for this
persistence type. The path must specify the file’s location relative to the top level of
the EJB’s .jar deployment file or deployment directory.
Example
See “persistence-type” on page 10-54 for an example that shows the complete
persistence-type definition for WebLogic Server RDBMS-based persistence.
type-version
Range of values: Valid string
Requirements: Required only for entity EJBs that use container-managed persistence services.
Function
The type-version element identifies the version of the specified persistence type.
Note: If you use WebLogic Server RDBMS-based persistence, the specified version
must exactly match the RDBMS persistence version for the WebLogic Server
release. Specifying an incorrect version results in the error:
weblogic.ejb.persistence.PersistenceSetupException: Error
initializing the CMP Persistence Type for your bean: No installed
Persistence Type matches the signature of (identifier
‘Weblogic_CMP_RDBMS’, version ‘version_number’).
Example
See persistence-type for an example that shows the complete persistence-type
definition for WebLogic Server RDBMS-based persistence.
weblogic-ejb-jar
Range of values: N/A
Requirements: N/A
Function
weblogic-ejb-jar is the root element of the weblogic component of the EJB
deployment descriptor.
weblogic-enterprise-bean
Range of values:
Default value:
Requirements:
Function
The weblogic-enterprise-bean element contains the deployment information for
a bean that is available in WebLogic Server.
l clustering-descriptor
l transaction-descriptor
l reference-descriptor
l jndi-name
l transaction-isolation
n security-role-assignment
caching-descriptor
The caching-descriptor stanza affects the number of EJBs in the WebLogic Server
cache as well as the length of time before EJBs are passivated or pooled. The entire
stanza, as well as each of its elements, is optional. WebLogic Server uses default
values where no elements are defined.
<max-beans-in-free-pool>500</max-beans-in-free-pool>
<initial-beans-in-free-pool>50</initial-beans-in-free-pool>
<max-beans-in-cache>1000</max-beans-in-cache>
<idle-timeout-seconds>20</idle-timeout-seconds>
<cache-strategy>Read-Write</cache-strategy>
<read-timeout-seconds>0</read-timeout-seconds>
</caching-descriptor>
max-beans-in-free-pool
Note: This element is valid only for stateless session EJBs.
WebLogic Server maintains a free pool of EJBs for every bean class. This optional
element defines the size of the pool. By default, max-beans-in-free-pool has no
limit; the maximum number of beans in the free pool is limited only by the available
memory. See “Activating and Using Stateful Session EJB Instances” on page 4-5 in
“The WebLogic Server EJB Container and Supported Services” on page 4-1 for more
information.
initial-beans-in-free-pool
Note: This element is valid only for stateless session EJBs.
max-beans-in-cache
Note: This element is valid only for stateful session EJBs and entity EJBs.
This element specifies the maximum number of objects of this class that are allowed
in memory. When max-bean-in-cache is reached, WebLogic Server passivates
some EJBs that have not been recently used by a client. max-beans-in-cache also
affects when EJBs are removed from the WebLogic Server cache, as described in
“Removing Stateful Session EJB Instances” on page 4-6.
The default value of max-beans-in-cache is 100.
idle-timeout-seconds
idle-timeout-seconds defines the maximum length of time a stateful EJB should
remain in the cache. After this time has elapsed, WebLogic Server may remove the
bean instance if the number of beans in cache approaches the limit of
max-beans-in-cache. See “EJB Life Cycle in WebLogic Server” on page 4-2 for
more information.
idle-timeout-seconds defaults to 600 if you do not define the element.
cache-strategy
The cache-strategy element can be one of the following:
n Read-Write
n Read-Only
The default value is Read-Write. See “Setting Entity EJBs to Read-Only” on page
4-13 for more information.
read-timeout-seconds
The read-timeout-seconds element specifies the number of seconds between
ejbLoad() calls on a Read-Only entity bean. By default, read-timeout-seconds
is set to 600 seconds. If you set this value to 0, WebLogic Server calls ejbLoad only
when the bean is brought into the cache.
persistence-descriptor
The persistence-descriptor stanza specifies persistence options for entity EJBs.
The following shows all elements contained in the persistence-descriptor
stanza:
<persistence-descriptor>
<is-modified-method-name>. . .</is-modified-method-name>
<delay-updates-until-end-of-tx>. .
.</delay-updates-until-end-of-tx>
<persistence-type>
<type-identifier>. . .</type-identifier>
<type-version>. . .</type-version>
<type-storage>. . .</type-storage>
</persistence-type>
<db-is-shared>. . .</db-is-shared>
<stateful-session-persistent-store-dir>
. . .
</stateful-session-persistent-store-dir>
<persistence-use>. . .</persistence-use>
</persistence-descriptor>
is-modified-method-name
is-modified-method-name specifies a method that WebLogic Server calls when the
EJB is stored. The specified method must return a boolean value. If no method is
specified, WebLogic Server always assumes that the EJB has been modified and
always saves it.
delay-updates-until-end-of-tx
Set this property to true (the default), to update the persistent store of all beans in a
transaction at the completion of the transaction. This generally improves performance
by avoiding unnecessary updates. However, it does not preserve the ordering of
database updates within a database transaction.
persistence-type
A persistence-type defines a persistence service that can be used by an EJB. You
can define multiple persistence-type entries in weblogic-ejb-jar.xml for
testing with multiple persistence services. Only the persistence type defined in
“persistence-use” on page 10-94 is used during deployment.
Note: The specified version must exactly match the RDBMS persistence version for
the WebLogic Server release. Specifying an incorrect version results in the
error:
weblogic.ejb.persistence.PersistenceSetupException: Error
initializing the CMP Persistence Type for your bean: No installed
Persistence Type matches the signature of (identifier
‘Weblogic_CMP_RDBMS’, version ‘version_number’).
n type-storage defines the full path of the file that stores data for this
persistence type. The path must specify the file’s location relative to the top level
of the EJB’s .jar deployment file or deployment directory.
WebLogic Server RDBMS-based persistence generally uses an XML file named
weblogic-cmp-rdbms-jar.xml to store persistence data for a bean. This file is
stored in the META-INF subdirectory of the .jar file.
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>5.1.0</type-version>
<type-storage>META-INF\weblogic-cmp-rdbms-jar.xml</type-stora
ge>
</persistence-type>
db-is-shared
The db-is-shared element applies only to entity beans. When set to true (the
default value), WebLogic Server assumes that EJB data could be modified between
transactions and reloads data at the beginning of each transaction. When set to false,
WebLogic Server assumes that it has exclusive access to the EJB data in the persistent
store. See “Using db-is-shared to Limit Calls to ejbLoad()” on page 4-10 for more
information.
stateful-session-persistent-store-dir
stateful-session-persistent-store-dir specifies the file system directory
where WebLogic Server stores the state of passivated stateful session bean instances.
persistence-use
The persistence-use property is similar to persistence-type, but it defines the
persistence service actually used during deployment. persistence-use uses the
type-identifier and type-version elements defined in a persistence-type to
identify the service.
For example, to actually deploy an EJB using the WebLogic Server RDBMS-based
persistence service defined in persistence-type, the persistence-use stanza
would resemble:
<persistence-use>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>5.1.0</type-version>
</persistence-use>
clustering-descriptor
The clustering-descriptor stanza defines the replication properties and behavior
for EJBs deployed in a WebLogic Server cluster. The clustering-descriptor
stanza and each of its elements are optional, and are not applicable to single-server
systems.
The following shows all elements contained in the clustering-descriptor stanza:
<clustering-descriptor>
<home-is-clusterable>. . .</home-is-clusterable>
<home-load-algorithm>. . .</home-load-algorithm>
<home-call-router-class-name>. .
.</home-call-router-class-name>
<stateless-bean-is-clusterable>. .
.</stateless-bean-is-clusterable>
<stateless-bean-load-algorithm>. .
.</stateless-bean-load-algorithm>
<stateless-bean-call-router-class-name>. .
.</stateless-bean-call-router-class-name>
<stateless-bean-methods-are-idempotent>. .
.</stateless-bean-methods-are-idempotent>
</clustering-descriptor>
home-is-clusterable
You can set this element to either true or false. When home-is-clusterable is
true, the EJB can be deployed from multiple WebLogic Servers in a cluster. Calls to
the home stub are load-balanced between the servers on which this bean is deployed,
and if a server hosting the bean is unreachable, the call automatically fails over to
another server hosting the bean.
home-load-algorithm
home-load-algorithm specifies the algorithm to use for load balancing between
replicas of the EJB home. If this property is not defined, WebLogic Server uses the
algorithm specified by the server property,
weblogic.cluster.defaultLoadAlgorithm.
n random: Replicas of the EJB home are deployed randomly among the servers
hosting the bean.
home-call-router-class-name
home-call-router-class-name specifies the custom class to use for routing bean
method calls. This class must implement
weblogic.rmi.extensions.CallRouter(). If specified, an instance of this class is
called before each method call. The router class has the opportunity to choose a server
to route to based on the method parameters. The class returns either a server name or
null, which indicates that the current load algorithm should select the server.
stateless-bean-is-clusterable
This property is similar to home-is-clusterable, but it is applicable only to
stateless session EJBs.
stateless-bean-load-algorithm
This property is similar to home-load-algorithm, but it is applicable only to
stateless session EJBs.
stateless-bean-call-router-class-name
This property is similar to home-call-router-class-name, but it is applicable only
to stateless session EJBs.
stateless-bean-methods-are-idempotent
You can set this element to either true or false. Set
stateless-bean-methods-are-idempotent to true only if the bean is written
such that repeated calls to the same method with the same arguments has exactly the
same effect as a single call. This allows the failover handler to retry a failed call
without knowing whether the call actually completed on the failed server. Setting this
property to true makes it possible for the bean stub to automatically recover from any
failure as long as another server hosting the bean can be reached.
transaction-descriptor
The transaction-descriptor stanza contains elements that define transaction
behavior in WebLogic Server. Currently, this stanza includes only one element:
<transaction-descriptor>
<trans-timeout-seconds>20</trans-timeout-seconds>
<transaction-descriptor>
trans-timeout-seconds
The trans-timeout-seconds element specifies the maximum duration for the EJB’s
container-initiated transactions. If a transaction lasts longer than
trans-timeout-seconds, WebLogic Server rolls back the transaction.
reference-descriptor
The reference-descriptor stanza maps references in the ejb-jar.xml file to the
JNDI names of actual resource factories and EJBs available in WebLogic Server.
<resource-description>
<res-ref-name>. . .</res-ref-name>
<jndi-name>. . .</jndi-name>
</resource-description>
<ejb-reference-description>
<ejb-ref-name>. . .</ejb-ref-name>
<jndi-name>. . .</jndi-name>
</ejb-reference-description>
</reference-descriptor>
resource-description
The following elements define an individual resource-description:
ejb-reference-description
The following elements define an individual ejb-reference-description:
n ejb-ref-name specifies an EJB reference name. This is the reference that the
EJB provider places within the ejb-jar.xml deployment file.
enable-call-by-reference
By default, EJB methods called from within the same server pass arguments by
reference. This increases the performance of method invocation since parameters are
not copied.
jndi-name
The jndi-name element specifies a jndi-name for a bean, resource, or reference.
transaction-isolation
The transaction-isolation stanza specifies the transaction isolation level for EJB
methods. The stanza consists of one or more isolation-level elements that apply
to a range of EJB methods. For example:
<transaction-isolation>
<isolation-level>Serializable</isolation-level>
<method>
<description>...</description>
<ejb-name>...</ejb-name>
<method-intf>...</method-intf>
<method-name>...</method-name>
<method-params>...</method-params>
</method>
</transaction-isolation>
isolation-level
isolation-level defines a valid transaction isolation level to apply to specific EJB
methods. The following are possible values for isolation-level:
Refer to your database documentation for more information on the implications and
support for different isolation levels.
method
The method stanza defines the EJB methods to which an isolation level applies.
method defines a range of methods using the following elements:
n ejb-name identifies the EJB to which WebLogic Server applies isolation level
properties.
n method-params is an optional stanza that lists the Java types of each of the
method’s parameters. The type of each parameter must be listed in order, using
individual method-param elements within the method-params stanza.
For example, the following method stanza designates all methods in the
“AccountBean” EJB:
<method>
<ejb-name>AccountBean</ejb-name>
<method-name>*</method-name>
</method>
<ejb-name>AccountBean</ejb-name>
<method-intf>Remote</method-intf>
<method-name>*</method-name>
</method>
security-role-assignment
The security-role-assignment stanza maps application roles in the ejb-jar.xml
file to the names of security principals available in WebLogic Server.
n role-name is the application role name that the EJB provider placed in the
ejb-jar.xml deployment file.
11 weblogic-cmp-rdbms-
jar.xml Document Type
Definitions
The chapter describes both the EJB 5.1 and EJB 6.0 deplopyment descriptor elements
found in the weblogic-cmp-rdbms-jar.xml file, the weblogic-specific XML
document type definitions (DTD) file. Use these definitions to create the
WebLogic-specific weblogic-cmp-rdbms-jar.xml file that is part of your EJB
deployment.
n weblogic-ejb-jar.xml
n weblogic-cmp-rdbms-jar.xml
You package these three XML files with the EJB and other classes into a deployable
EJB component, usually a JAR file, called ejb.jar.
The correct text for the PUBLIC element for the WebLogic Server-specific
weblogic-cmp-rdbms-jar.xml files are as follows.
The correct text for the PUBLIC elements for the Sun Microsystem-specific ejb-jar
files are as follows.
XML files with incorrect header information may yield error messages similar to the
following, when used with a utility that parses the XML (such as ejbc):
SAXException: This document may not have the identifier ‘identifier_name’
identifier_name generally includes the invalid text from the PUBLIC element.
instead use the DTD locations that were installed along with the server. However, the
DOCTYPE header information must include a valid URL syntax in order to avoid
parser errors.
Note: Most browsers do not display the contents of files having the .dtd extension.
To view the DTD file contents in your browser, save the links as text files and
view them with a text editor.
weblogic-cmp-rdbms-jar.xml
The following links provide the public DTD locations for the
weblogic-cmp-rdbms-jar.xml deployment files used with WebLogic Server:
ejb-jar.xml
The following links provide the public DTD locations for the ejb-jar.xml
deployment files used with WebLogic Server:
Note: Refer to the appropriate JavaSoft EJB specification for a description of the
ejb-jar.xml deployment descriptors.
6.0 weblogic-cmp-rdbms-jar.xml
Deployment Descriptor File Structure
weblogic-cmp-rdbms-jar.xml defines deployment descriptors for a entity EJBs
that uses WebLogic Server RDBMS-based persistence services. The EJB 2.0 container
uses a version of weblogic-cmp-rdbms-jar.xml that is different from the one
shipped with WebLogic Server Version 5.1. See Locking Services for Entity EJBs for
more information.
You can continue to use the earlier weblogic-cmp-rdbms-jar.xml DTD for EJB 1.1
beans that you will deploy on the WebLogic Server Version 6.0. However, if you want
to use any of the new CMP 2.0 features, you must use the new DTD described below.
The top-level element of the WebLogic Server 6.0 weblogic-cmp-rdbms-jar.xml
consists of a weblogic-rdbms-jar stanza:
description
weblogic-version
weblogic-rdbms-jar
weblogic-rdbms-bean
ejb-name
data-source-name
table-name
field-name
field-map
field-group
weblogic-query
delay-database-insert-until
automatic-key-generation
weblogic-rdbms-relation
relation-name
table-name
weblogic-relationship-role
6.0 weblogic-cmp-rdbms-jar.xml
Deployment Descriptor Elements
n “automatic-key-generation” on page 11-8
n “cmp-field” on page 11-9
automatic-key-generation
Range of values: n/a
Requirements: Optional.
Function
The automatic-key-generation element specifies the use of the Sequence/Key
Generation feature.
Example
The XML stanza can contain the elements shown here:
<automatic-key-generation>
<generator-type>ORACLE</generator-type>
<generator-name>test_sequence</generator-name>
<key-cache-size>10</key-cache-size>
</automatic-key-generation>
<automatic-key-generation>
<generator-type>SQL-SERVER</generator-type>
</automatic-key-generation>
<automatic-key-generation>
<generator-type>NAMED_SEQUENCE_TABLE</generator-type>
<generator-name>MY_SEQUENCE_TABLE_NAME</generator-name>
<key-cache-size>100</key-cache-size>
</automatic-key-generation>
cmp-field
Range of values: Valid name
Requirements: Field is case sensitive and must match the name of the field in the bean and must also
have a cmp-entry entry in the ejb-jar.xml.
Function
This name specifies the mapped field in the bean instance which should be populated
with information from the database.
Example
See “field-map” on page 11-21.
cmr-field
Range of values: Valid name
Requirements: The field referenced in cmr-field must have a matching cmr-field entry in the
ejb-jar.xml.
Function
The cmr-field element specifies the name of a cmr-field.
Example
The XML stanza can contain the elements shown here:
<weblogic-rdbms-jar>
<weblogic-rdbms-relation>
<field-group>employee</field-group>
<cmr-field>stock options</cmr-field>
</weblogic-rdbms-relation>
</weblogic-rdbms-jar>
column-map
Range of values: n/a.
Function
This element represents the mapping of a foreign key column in one table in the
database to a corresponding primary key. The two columns may or may not be in the
same table. The tables to which the column belong are implicit from the context in
which the column-map element appears in the deployment descriptor.
Example
The XML stanza can contain the elements shown here:
<weblogic-rdbms-jar>
<weblogic-rdbms-bean>
<column-map
<foreign-key-column>account-id</foreign-key-column>
<key-column>id</key-column>
</column-map>
</weblogic-rdbms-bean>
</weblogic-rdbms-jar>
create-default-dbms-tables
Range of values: True | False.
Requirements: Use this element only for convenience during the development and prototyping phases.
This is because the Table Schema in the DBMS CREATE statement used will be the
container’s best approximation of the definition. A production environment most likely,
will require a more precise schema definition.
Function
The create-default-dbms-table element turns on or off a feature that
automatically creates a default table based on the descriptions in the deployment files
and the bean class. When set to False, this feature is turned off and table will not
automatically be generated. When set to True, this feature is turned on and the table is
automatically created. If TABLE CREATION fails, a Table Not Found error is thrown
and the table must be created by hand.
Example
The following example specifies the create-default-dbms-tables element.
<create-default-dbms-tables>True</create-default-dbms-tables>
data-source-name
Range of values: Valid name of the data source used for all data base connectivity for this bean.
Requirements: Must be defined as a standard WebLogic Server JDBC data source for database
connectivity. See Programming WebLogic JDBC for more information.
Function
The data-source-name that specifies the JDBC data source name to be used for all
database connectivity for this bean.
Example
See “table-name” on page 11-37.
db-cascade-delete
Range of values:
Requirements: Only supported for Oracle database. Can only be specified for one-to-one or
one-to-many relationships.
Function
The db-cascade-delete element specifies whether the database cascade feature is
turned on. If this element is not specified, WebLogic Server assumes that database
cascade delete is not specified.
Example
See “Cascade Delete Method” on page 5-16.
dbms-column
Range of values: Valid name
Requirements: dbms-column is case maintaining, although not all database are case sensitive.
Function
The name of the database column to which the field should be mapped.
Example
See “field-map” on page 11-21.
dbms-column-type
Range of values: Valid name
Function
The dbms-column-type element maps the current field to a Blob or Clob in an Oracle
database or a LongString in a Sybase database. This element can be one of the
following:
n OracleBlob
n OracleCLob
n LongString
Example
<field-map>
<cmp-field>photo</cmp-field>
<dbms-column>PICTURE</dbms-column>
<dbms_column-type>OracleBlob</dbms-column-type>
</field-map>
delay-database-insert-until
Range of values:
Requirements: Database insert is delayed until after ejbPostCreate when a cmr-field is mapped
to a foreign-key column that does not allow null values. In this case, the
cmr-field must be set to a non-null value in ejbPostCreate before the bean is
inserted into the database.
The cmr-fields may not be set during ejbCreate, before the primary key of the
bean is known.
Function
The delay-database-insert-until element specifies the precise time when a new
bean that uses RDBMS CMP is inserted into the database.
It is advisable to delay the database insert until after the ejbPostCreate method
modifies the persistent fields of the bean. This can yield better performance by
avoiding an unnecessary store operation.
For maximum flexibility, you should avoid creating related beans in your
ejbPostCreate method. This may make delaying the database insert impossible if
database constraints prevent related beans from referring to a bean that has not yet been
created.
Example
The following example specifies the delay-database-insert-until element.
<delay-database-insert-until>ejbPostCreate</delay-database-insert
-until>
ejb-name
Range of values: Valid name of an EJB.
Requirements: Must match the ejb-name of the cmp entity bean defined in the ejb-jar.xml.
Function
The name that specifies an EJB as defined in the ejb-cmp-rdbms.xml. This name must
match the ejb-name of a cmp entity bean contained in the ejb-jar.xml.
Example
See “table-name” on page 11-37.
enable-tuned-updates
Note: This deployment descriptor applies to EJB 1.1 only.
Requirements:
Function
The enable-tuned-updates element specifies that when ejbStore is called that the
EJB container automatically determine which container-managed fields have been
modified and then writes only those fields back to the database.
Example
The following examples shows how to specify the enable-tuned-updates element.
<enable-tuned-updates>True</enable-tuned-updates>
field-group
Range of values: Valid name
Default value: A special group named default is used for finders and relationships that have no group
specified.
Requirements: The default group contains all of a bean’s cmp-fields, but none of its cmr-fields.
Function
The field-group element represents a subset of the cmp and cmr-fields of a bean.
Related fields in a bean can be put into groups that are faulted into memory together
as a unit. A group can be associated with a finder or relationship, so that when a bean
is loaded as the result of executing a finder or following a relationship, only the fields
specified in the group are loaded.
A field may belong to multiple groups. In this case, the getXXX method for the field
faults in the first group that contains the field.
Example
The XML stanza can contain the elements shown here:
<weblogic-rdbms-bean>
<ejb-name>XXXBean</ejb-name>
<field-group>
<group-name>medical-data</group-name>
<cmp-field>insurance</cmp-field>
<cmr-field>doctors</cmr-fields>
</field-group>
</weblogic-rdbms-bean>
field-map
Range of values: Valid name
Requirements: Field mapped to the column in the database must correspond to a cmp field in the bean.
Function
The name of the mapped field for a particular column in a database that corresponds
to a cmp field in the bean instance.
Example
The XML stanza can contain the elements shown here:
<weblogic-rdbms-jar>
<weblogic-rdbms-bean>
<field-map>
<cmp-field>accountId</cmp-field>
<dbms-column>id</dbms-column>
</field-map>
<field-map>
<cmp-field>balance</cmp-field>
<dbms-column>bal</dbms-column>
</field-map>
<field-map>
<cmp-field>accountType</cmp-field>
<dbms-column>type</dbms-column>
</field-map>
</weblogic-rdbms-bean>
</weblogic-rdbms-jar>
foreign-key-column
Range of values: Valid name
Function
The foreign-key-column element represents a column of a foreign key in the
database.
Example
See “column-map” on page 11-11.
generator-name
Range of values: n/a
Requirements: Optional.
Function
The generator-name element is used to specify the name of the generator.
For example;
Example
See “automatic-key-generation” on page 11-8.
generator-type
Range of values: n/a
Requirements: Optional
Function
The generator-type element specifies the key generation method to use. The options
include:
n ORACLE
n SQL_SERVER
n NAMED_SEQUENCE_TABLE
Example
See “automatic-key-generation” on page 11-8.
group-name
Range of values: Valid name
Requirements: n/a
Function
The group-name element specifies the name of a field group.
Example
The XML stanza can contain the elements shown here:
<weblogic-rdbms-jar>
<weblogic-rdbms-relation>
<field-group>employee</field-group>
<cmr-field>stock options</cmr-field>
<group-name>financial data</group-name>
</weblogic-rdbms-relation>
</weblogic-rdbms-jar>
include-updates
Range of values: True | False
Requirements: The default value, which is False, provides the best performance.
Function
The include-updates element specifies that updates made during the current transaction
must be reflected in the result of a query. If this element is set to True, the container
will flush all changes made by the current transaction to disk before executing the
query.
Example
The XML stanza can contain the elements shown here:
<include-updates>False</include_updates>
key-cache-size
Range of values: n/a
Default value: 1
Requirements: Optional
Function
The key-cache-size element specifies the optional size of the primary key cache
available in the automatic primary key generation feature.
Example
See “automatic-key-generation” on page 11-8.
key-column
Range of values: Valid name
Function
The key-column element represents a column of a primary key in the database.
Example
See “column-map” on page 11-11.
max-elements
Range of values: n/a
Requirements: n/a
Function
max-elements specifies the maximum number of elements that should be returned by
a multi-valued query. This element is similar to the maxRows feature in JDBC.
Example
The XML stanza can contain the elements shown here:
<max-elements>100</max-elements>
method-name
Range of values: n/a
Function
The method-name element specifies the name of a finder or ejbSelect method.
Example
See “weblogic-query” on page 11-39.
method-param
Range of values: Valid name
Requirements: n/a
Function
The method-param element contains the fully qualified Java type name of a method
parameter.
Example
The XML stanza can contain the elements shown here:
<method-param>java.lang.String</method-param>
method-params
Range of values: list of valid names
Requirements: n/a
Function
The method-params element contains an ordered list of the fully-qualified Java type
names of the method parameters.
Example
See “weblogic-query” on page 11-39.
query-method
Range of values: n/a
Requirements: n/a
Function
The query-method element specifies the method that is associated with a
weblogic-query. It also uses the same format as the ejb-jar.xml descriptor.
Example
See “weblogic-query” on page 11-39.
relation-name
Range of values: Valid name
Function
The relation-name element specifies the name of a relation.
Example
The XML stanza can contain the elements shown here:
<weblogic-rdbms-jar>
<weblogic-rdbms-relation>
<relation-name>stocks-holders</relation-name>
<table-name>stocks</table-name>
</weblogic-rdbms-relation>
</weblogic-rdbms-jar>
relationship-role-name
Range of values: Valid name
Function
The relationship-role-name element specifies the name of a relationship role.
Example
The XML stanza can contain the elements shown here:
<weblogic-rdbms-jar>
<weblogic-rdbms-relation>
<weblogic-relationship-role>stockholder</weblogic-
relationship-role>
<relationship-role-name>stockholders</relationship-
role-name>
</weblogic-rdbms-relation>
</weblogic-rdbms-jar>
sql-select-distinct
Range of values: True | False
Requirements: The Oracle database does not allow you to use a SELECT DISTINCT in conjunction
with a FOR UPDATE clause. Therefore, you cannot use the sql-select-distinct
element if any bean in the calling chain has a method with a
transaction-isolation element set to the isolation-level sub element with
a value of TRANSACTION_READ_COMMITED_FOR_UPDATE You specify the
transaction-isolation element in the weblogic-ejb-jar.xml file.
Function
The sql-select-distinct element controls whether the generated SQL SELECT
statement will contain a a DISTINCT qualifer. Using the DISTINCT qualifer caused
the database to return unique rows.
Example
The XML example contains the element shown here:
<sql-select-distinct>True</sql-select-distinct>
table-name
Range of values: Valid, fully qualified SQL name of the source table in the database.
Function
The fully qualified SQL name of the table. The user defined for the data-source for
this bean must have read and write privileges for this table, but does not necessarily
need schema modification privileges.
Example
The XML stanza can contain the elements shown here:
<weblogic-rdbms.jar>
<weblogic-rdbms-bean>
<ejb-name>containerManaged</ejb-name>
<data-source-name>examples-dataSource-demoPool</data-source-name>
<table-name>ejbAccounts</table-name>
</weblogic-rdbms-bean>
</weblogic-rdbms-jar>
weblogic-ql
Range of values: n/a
Requirements: n/a
Function
The weblogic-ql element specifies a query that contains a WebLogic specific
extension to the ejb-ql language. You should specify queries that only use standard
EJB-QL language features in the ejb-jar.xml deployment descriptor.
Example
See “weblogic-query” on page 11-39.
weblogic-query
Range of values: n/a
Requirements: n/a
Function
The weblogic-query element allows you to associate WebLogic specific attributes
with a query, as necessary. For example, weblogic-query can be used to specify a
query that contains a WebLogic specific extension to EJB-QL. Queries that do not take
advantage of WebLogic extensions to EJB-QL should be specified in the
ejb-jar.xml deployment descriptor.
Example
The XML stanza can contain the elements shown here:
<weblogic-query>
<query-method>
<method-name>findBigAccounts</method-name>
<method-params>
<method-param>double</method-param>
</method-params>
<query-method>
<weblogic-ql>WHERE BALANCE>10000
ORDERBY NAME</weblogic-ql>
</weblogic-query>
weblogic-relationship-role
Range of values: Valid name
Function
The weblogic-relationship-role element is used to express a mapping from a
foreign key to a primary key. Only one mapping is specified for one-to-one
relationships when the relationship is local. However, with a many-to-many
relationship, you must specify two mappings
Multiple column mappings are specified for a single role, it the key is complex. No
column-map is specified if the role is just specifying a group-name.
Example
The XML stanza can contain the elements shown here:
<weblogic-rdbms-jar>
<weblogic-rdbms-relation>
<relation-name>stocks-holders</relation-name>
<table-name>stocks</table-name>
<weblogic-relationship-role>stockholder
</weblogic-relationship-role>
</weblogic-rdbms-relation>
</weblogic-rdbms-jar>
5.1 weblogic-cmp-rdbms-jar.xml
Deployment Descriptor File Strucutre
weblogic-cmp-rdbms-jar.xml defines deployment elements for a single entity EJB
that uses WebLogic Server RDBMS-based persistence services. See “Locking
Services for Entity EJBs” on page 4-34 for more information.
weblogic-version
<weblogic-enterprise-bean>
<pool-name>finance_pool</pool-name>
<schema-name>FINANCE_APP</schema-name>
<table-name>ACCOUNT</table-name>
<attribute-map>
<object-link>
<bean-field>accountID</bean-field>
<dbms-column>ACCOUNT_NUMBER</dbms-column>
</object-link>
<object-link>
<bean-field>balance</bean-field>
<dbms-column>BALANCE</dbms-column>
</object-link>
</attribute-map>
<finder-list>
<finder>
<method-name>findBigAccounts</method-name>
<method-params>
<<method-param>double</method-param>
</method-params>
<finder-expression>. . .</finder-expression>
</finder>
</finder-list>
</weblogic-enterprise-bean>
5.1 weblogic-cmp-rdbms-jar.xml
Deployment Descriptor Elements
pool-name
pool-name specifies name of the WebLogic Server connection pool to use for this
EJB’s database connectivity. See Using connection pools for more information.
schema-name
schema-name specifies the schema where the source table is located in the database.
This element is required only if you want to use a schema that is not the default schema
for the user defined in the EJB’s connection pool.
Note: This field is case sensitive, although many SQL implementations ignore case.
table-name
table-name specifies the source table in the database. This element is required in all
cases.
Note: The user defined in the EJB’s connection pool must have read and write
privileges to the specified table, though not necessarily schema modification
privileges. This field is case sensitive, although many SQL implementations
ignore case.
attribute-map
The attribute-map stanza links a single field in the EJB instance to a particular
column in the database table. The attribute-map must have exactly one entry for
each field of an EJB that uses WebLogic Server RDBMS-based persistence.
object-link
Each attribute-map entry consists of an object-link stanza, which represents a
link between a column in the database and a field in the EJB instance.
bean-field
bean-field specifies the field in the EJB instance that should be populated from the
database. This element is case sensitive and must precisely match the name of the field
in the bean instance.
The field referenced in this tag must also have a cmp-field element defined in the
ejb-jar.xml file for the bean.
dbms-column
dbms-column specifies the database column to which the EJB field is mapped. This
tag is case sensitive, although many databases ignore the case.
Note: WebLogic Server does not support quoted RDBMS keywords as entries to
dbms-column. For example, you cannot create an attribute map for column
names such as “create” or “select” if those names are reserved in the
underlying datastore.
Finder Elements
This section describes the finder elements.
finder-list
The finder-list stanza defines the set of all finders that are generated to locate sets
of beans. See “Writing for RDBMS Persistence for EJB 1.1 CMP” on page 5-4 for
more information.
finder-list must contain exactly one entry for each finder method defined in the
home interface, except for findByPrimarykey. If an entry is not provided for
findByPrimaryKey, one is generated at compilation time.
finder
The finder stanza describes a finder method defined in the home interface. The
elements contained in the finder stanza enable WebLogic Server to identify which
method in the home interface is being described, and to perform required database
operations.
method-name
method-name defines the name of the finder method in the home interface. This tag
must contain the exact name of the method.
method-params
The method-params stanza defines the list of parameters to the finder method being
specified in method-name.
Note: WebLogic Server compares this list against the parameter types for the finder
method in the EJB’s home interface; the order and type for the parameter list
must exactly match the order and type defined in the home interface.
method-param
method-param defines the fully-qualified name for the parameter’s type. The type
name is evaluated into a java.lang.Class object, and the resultant object must
precisely match the respective parameter in the EJB’s finder method.
You can specify primitive parameters using their primitive names (such as “double” or
“int”). If you use a non-primitive data type in a method-param element, you must
specify a fully qualified name. For example, use java.sql.Timestamp rather than
Timestamp. If you do not use a qualified name, ejbc generates an error message when
you compile the deployment unit.
finder-query
finder-query specifies the WebLogic Query Language (WLQL) string that is used
to retrieve values from the database for this finder. See “Using WebLogic Query
Language (WLQL) for EJB 1.1 CMP” on page 5-6 for more information.
Note: Always define the text of the finder-query value using the XML CDATA
attribute. Using CDATA ensures that any special characters in the WLQL string
do not cause errors when the finder is compiled.
finder-expression
finder-expression specifies a Java language expression to use as a variable in the
database query for this finder.
Note: Future versions of the WebLogic Server EJB container will use the EJB QL
query language (as required by the EJB 2.0 specification). EJB QL does not
provide support for embedded Java expressions. Therefore, to ensure easier
upgrades to future EJB containers, create entity EJB finders without
embedding Java expressions in WLQL.