|
|
|
Enterprise JavaBeans
November 2003 |
|
This FAQ addresses frequently asked questions relating to Enterprise JavaBeans(EJB)
aspects of Oracle Application Server Containers for J2EE 10g (9.0.4) and is
broken into the following sections:
Common Questions
-
What is the level of support for EJB specifications for various releases
of Oracle Application Server Containers for J2EE (OC4J)?
| Product
Version |
Level
of support |
| OC4J
9.0.4 |
EJB
2.0
EJB-QL extensions
|
| OC4J
9.0.3 |
EJB
2.0 |
| OC4J
9.0.2 |
EJB
1.1
Some features of EJB 2.0 |
| OC4J
1.0.2.x |
EJB
1.1 |
- When will OC4J support the EJB 2.1 specification?
EJB 2.1 is not yet finalized and OC4J will support EJB 2.1 soon after J2EE
1.4 gets finalized.
- Where can I find the OC4J EJB Developer's Guide?
Documentation for all Oracle products is available from the Oracle Technology
Network (OTN) at http://otn.oracle.com/documentation/content.html.
The EJB Developer's Guide is available with the OC4J documentation set at
http://download.oracle.com/docs/cd/B10324-01/index.htm.
- Are there any samples available for EJB?
Several EJB samples are available for download from Oracle
Technology Network. You can find How-Tos
from the OC4J Home Page. Additional samples are available from the
OC4J
Samples Corner.
-
Can I use a third-party database like DB2, SQLServer with EJBs deployed
in OC4J?
Yes, OC4J supports third-party databases like DB2, SQLServer, Informix,
Sybase, etc by using DataDirect JDBC drivers. These drivers can be downloaded
from Oracle Technology Network for exclusive use with OC4J.
- Are there any changes to the default values in 9.0.4?
Yes, there are several changes and these are as follows
- Lazy loading for CMP finder methods is now turned off.
- For relationship mapping for a one-to-many relationship, the default
scenario used an association table in 9.0.3 and now, the default is to
use a foreign key.
- The default value for the trans-attribute
for CMP 2.0 entity beans is changed to Required.
- The max-tx-retries default
value is zero.
- The max-instances default
value is set to zero (unlimited) for all EJBs.
For more details, see the Oracle Application Server 10g (9.0.4) Enterprise
JavaBeans Developer's Guide.
Top of Page
Accessing EJBs
-
What are the different initial context factories for use in OC4J?
There are three initial context factories that are used for OC4J. They
are the ApplicationClientInitialContextFactory,
the RMInitialContextFactory and the ApplicationInitalContextFactory.
They are described in detail in the OC4J Enterprise JavaBeans Developer's
Guide. A summary of the differences is listed below.
The ApplicationClientInitialContextFactory
is used when looking up remote objects from standalone application clients.
It uses the refs and ref-mappings found in application-client.xml and orion-application-client.xml.
It is the default initial context factory when the initial context is instantiated
in a Java application. It can be used for looking up remote EJBs in the
same application. It can also be used for looking up EJBs with local interface.
The RMIInitialContextFactory
is used when looking up remote objects between different containers. It
is also used when browsing the complete JNDI namespace and not using the
application context.
The ApplicationInitalContextFactory
is used when looking up remote objects in same application. It is the default
initial context factory in use inside the OC4J container. It uses the ref
and ref-mappings in the web.xml, orion-web.xml, ejb-jar.xml, and orion-ejb-jar.xml
to locate resources.
-
How do I call one EJB from another EJB?
There is an example on OTN that demonstrates how to call one EJB from
another EJB. This example is one session bean calling another session bean
but the principles apply globally.
You can access this sample from
http://otn.oracle.com/sample_code/tech/java/oc4j/content.html
-
What protocols can I use to access an EJB remotely?
You can use three protocols to access EJBs remotely. You can use ORMI
(Oracle's implementation of RMI Protocol) for Java clients, RMI-IIOP for
CORBA clients or ORMI tunneling over HTTP to access EJBs from remote client
through firewall. See the OC4J Services Guide for more information.
-
How can I remotely access an EJB deployed in OC4J standalone using ORMI?
You have to use the RMIInitialContextFactory
for accessing EJBs remotely. You can also use the ApplicationClientInitialContextFactory
if you are accessing EJBs from application client. The following
is an example code snippet of how you can use an EJB deployed in a standalone
OC4J instance.
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "welcome");
env.put(Context.PROVIDER_URL, "ormi://dpanda-us:23792/ejbsamples");
Context context = new InitialContext(env);
Object homeObject = context.lookup("MyCart");
CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class);
For application portability, Oracle recommends to use jndi.properties
instead of hardcoding the environment properties in client code.
-
How can I remotely access an EJB deployed in OC4J embedded in Oracle
Application Server using ORMI?
In an OC4J instance embedded in an Oracle Application Server environment
the RMI ports are assigned dynamically. If you are accessing an EJB in Oracle
Application Server you have to know the RMI ports assigned by OPMN. In Oracle9iAS
versions 9.0.2/9.0.3 you have to limit the port ranges for RMI to a specific
number e.g. 3101-3101 if you have only one JVM for your OC4J instance. Also
in the Oracle Application Server environment JAZNUserManager is the default
user manager. The following code snippet is an example of how you can access
an EJB in Oracle Application Server environment.
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "jazn.com/admin");
env.put(Context.SECURITY_CREDENTIALS, "welcome");
env.put(Context.PROVIDER_URL, "ormi://dpanda-us:3101/ejbsamples");
Context context = new InitialContext(env);
Object homeObject = context.lookup("MyCart");
CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class);
In 9.0.4 you can use the following type of lookup in the URL to lookup EJB
in Oracle Application Server environment and you do not have to know the
RMI port assigned to your OC4J instance. The following code snippet demonstrates
how to lookup an EJB in Oracle Application Server 10g (9.0.4)
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "welcome");
env.put(Context.PROVIDER_URL,"opmn:ormi://opmnhost:oc4j_inst1/ejbsamples");
Context context = new InitialContext(env);
Object homeObject = context.lookup("MyCart");
CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class);
For application portability, Oracle recommends to use jndi.properties
instead of hardcoding the environment properties in client code.
-
How can I access EJBs in OC4J using RMI-IIOP?
For accessing EJBs using RMI-IIOP you can either use ApplicationClientInitialContextFactory
or IIOPInitialContextFactory.
For standalone OC4J you can lookup the EJB using the corbaname e.g.corbaname::localhost:4444#/appname.
If you are using OC4J embedded in Oracle Application Server 10g (9.0.4)
you can use opmn:corbaname lookup
e.g. opmn:corbaname::dlsun74:6003:home#appname.
See the OC4J Services Guide for more information. Also there is a How-To
available for using RMI-IIOP for Java clients at http://otn.oracle.com/tech/java/oc4j/htdocs/oc4j-how-to.html
-
Do I need any OC4J specific jar files in the client while looking up
an EJB deployed in OC4J?
If you are looking up an EJB deployed in OC4J standalone environment
you need only to include oc4jclient.jar
in your classpath. If you are looking up an EJB deployed to an OC4J instance
in Oracle Application Server 10g (9.0.4) using opmn:ormi
then you need to package optic.jar.
Also you need to include servlet.jar, jms.jar, jmxri.jar, ejb.jar and jndi.jar
in your classpath.
- How do I access an EJB in another application deployed in the same container?
If you want to access an EJB in another application in the same OC4J container
you do not have to use RMIInitialContextFactory
and you can make the application that contains your application as the parent
of your application from your you are trying to access EJBs from e.g.
<application name="myApp" path="../applications/myapp.ear"
parent="parentEJB" auto-start="true" />
You can define ejb-ref or ejb-local-ref
in the deployment descriptor of your application and you can use the default
InitialContext to lookup your
EJB.
- I am trying to access a remote EJB from my web application and getting
an error "java.lang.NullPointerException: domain was null ". How
can I avoid this?
You have to use another environment property in your client while accessing
the EJB. If you are using OC4J 9.0.2.1 or above you have to set dedicated.rmicontext
to true. If you are using 9.0.2.0.0
you have to set dedicated.connection
to true. You no longer have to use this in 9.0.4.
The following is the code snippet that demonstrates how to use the additional
environment property:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "debu");
env.put(Context.PROVIDER_URL, "ormi://dpanda-us/ejbsamples");
env.put("dedicated.rmicontext","true"); // for 9.0.2.1
and above
// env.put("dedicated.connection","true"); // for 9.0.2.0.0
Context context = new InitialContext(env);
- Why do I receive a "javax.naming.NamingException: Error reading
application client descriptor: No location specified and suitable instance
found for the ejb-ref XXXX" error when I try to access my EJB with a
remote client?
To access a remote EJB from an application client, do the following:
a) Create a file named jndi.properties with the following properties:
java.naming.factory.initial=com.evermind.server.ApplicationClientInitialContextFactory
java.naming.provider.url=ormi://localhost/<applicationname>
java.naming.security.principal=admin
java.naming.security.credentials=123
b) Make sure that the file is accessible from the CLASSPATH.
c) In your META-INF directory, add the EJB reference in the application-client.xml
file that specifies the EJB you want to refer to.
Here is a sample application-client.xml file:
<?xml version="1.0"?>
<!DOCTYPE application-client PUBLIC "-//Sun Microsystems,
Inc.//DTD J2EE
Application Client 1.2//EN"
"http://java.sun.com/j2ee/dtds/application-client_1_2.dtd";>
<application-client>
<ejb-ref>
<ejb-ref-name>MyCart</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>CartHome</home>
<remote>Cart</remote>
</ejb-ref>
</application-client>
- How can I access EJBs through a firewall?
You have to use ORMI tunneling over http(s) to access EJBs behind a firewall.
Please refer to the OC4J Services Guide ORMI chapter how to setup ORMI-HTTP
tunneling.
- What are the things I've to do to access EJBs deployed in OC4J from a
third-party Web/EJB container like Tomcat?
You have to perform the following steps:
- Include oc4jclient.jar
in the remote container's classpath
- Package the interfaces (home/remote) of the EJBs with your application
- Use RMIInitialContextFactory to access the EJB.
- Why should I use PortableRemoteObject.narrow() in my remote lookup of
a home interface?
To support portability of your application, potentially using the RMI-IIOP
protocol for communication with your EJB, you should always use the PortableRemoteObject.narrow()
method instead of a direct cast operation when you look up an object using
JNDI.
- Can I lookup an EJB from a Startup/Shutdown Class?
In OC4J 9.0.4 there is a restriction that Startup/Shutdown classes can
lookup EJBs in the default application in the same container. However there
is no restriction in looking up remote EJBs deployed in another OC4J instance.
Top of Page
Packaging and Deployment
-
Do I need to package home/remote interfaces for EJBs referenced in
Web Module for co-located EJBs?
No, you do not have to package the home/remote interfaces with web modules
for co-located EJBs as the EJB classloader is a parent classloader to all
web modules for a J2EE application (EAR).
-
Can I use Manifest Class-Path entry in an ejb-jar to reference to helper
libraries?
OC4J supports Manifest Class-Path for ejb-jar for OC4J 9.0.2 and higher.
-
Can I read a property file or resource from EJB?
You can load a resource or property file from EJB. You have to use the
ContextClassloader to load
any resource from a J2EE application. The following code snippet shows how
to load a resource from a bean class. The resource has to be either packaged
in the EJB-JAR or available in a higher level in the code source for the
EJB module.
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/debu.properties");
-
Where should I put common classes that are used by more than one EJB?
If you have classes that can be used by more than one EJB, you can centralize
these classes in one of the following ways:
1) If two EJBs use the same classes, include theses classes in one of
the EJBs. Place both EJBs in the same JAR file. After deployment, both EJBs
will be
able to use the common classes.
2) Place the commonly used class files in a JAR file, which you place in
the $J2EE_HOME/lib directory
for 9.0.3 and lower and $J2EE_HOME/applib
for 9.0.4. Then all applications deployed in OC4J can use these supporting
classes.
3) Because "child applications can access classes that exist within
a "parent" application,
place the commonly used classes in a parent application. All EJBs
that use these classes should define the application that contains the common
classes as its parent by adding the parent attribute to its <application>
element in the server.xml file
as follows:
<application name="myApp" path="../applications/myapp.ear"
parent="ApplicationWithCommonClasses" auto-start="true"
/>
The parent attribute defines
an optional parent application,
where the default is the global application. The children see the namespace
of their parent application. This is used to share services such as EJBs
among multiple applications.
-
How do I force Oracle9iAS to keep the wrapper code for debugging purpose?
If you have to keep the generated wrapper code for debugging purpose
you have to start OC4J with a system property KeepWrapperCode
set to true. The wrapper code will be saved in the j2ee/home directory.
-
Does OC4J support hot and automatic deployment of EJB modules?
Yes, OC4J supports both hot and automatic deployment of EJB modules
and deployment of EJB modules does not require server restart. However Oracle
does not recommend use of automatic deployment i.e. replace new ejb-jar
modules in production environment. Automatic deployment is disabled in OC4J
instance embedded in Oracle Application Server.
-
I've made some modifications in orion-ejb-jar.xml
but redeployment of applications overwrites this file. How do I avoid this?
You have to package the modified orion-ejb-jar
in the META-INF directory
of your EJB-JAR module to avoid being overwritten during deployment.
- Can I package an external JDBC driver or XML parsers with my EJB modules?
OC4J does not support packaging of JDBC drivers or XML parsers with applications.
- How does OC4J know what DataSource to associate with a CMP entity bean?
The default DataSource
used depends on where the DataSource
is specified. You can specify the default
DataSource in one of the following descriptors.
Note: The order of sequence for the default DataSource
configuration is the same as listed below.
a) Set the data source attribute on the
<entity-deployment> element in the orion-ejb-jar.xml
file for the entity bean.
b) Set the default-datasource
attribute in the <orion-application>
element in the orion-application.xml
file that is specific to the application (within the EAR structure).
c) Set the default-datasource
attribute in the <orion-application>
element in the application.xml file
that is generic to all applications. Thus, this file is located in the config/
directory.
- How do I stop OC4J to create tables during deployment of CMP entity beans?
Set the autocreate-tables="false" attribute in the orion-application.xml
file and OC4J will stop creating tables upon deployment.
- How do you make OC4J auto-create tables on redeployment?
Set the autodelete-tables="true" attribute in the orion-application.xml
file or config/application.xml file, and OC4J re-creates the tables upon redeployment.
- I'm trying to deploy a CMP entity bean with a field type BigDecimal and
the table creation fails with an error. How do I work around this?
You have to perform the following steps prior to deploy your application.
- Define the mapping for java.math.BigDecimal in the database-schemas/oracle.xml
as follows:
<type-mapping type="java.math.BigDecimal" name="number(20,8)"
/>
- Use this schema in your data-source as follows:-
<data-source
class="com.evermind.sql.DriverManagerDataSource"
name="OracleDS"
ejb-location="jdbc/OracleDS"
schema="database-schemas/oracle.xml"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="scott"
password="tiger"
url="jdbc:oracle:thin:@localhost:1521:DEBU"
clean-available-connections-threshold="30"
rac-enabled="false"
inactivity-timeout="30"
/>
- Use this data-source for your EJBs
<orion-ejb-jar>
<enterprise-beans>
<entity-deployment name="BigDecimalTest" data-source="jdbc/OracleDS"
/>
</enterprise-beans>
- Do I need the database to be available for deploying an EJB module containing
a CMP entity bean?
No, you do not need the database to be available for deploying an EJB
module containing a CMP entity bean unless you want the deployment process
to automatically create tables for your CMP entity beans. However you will
need the database available for running the application.
- I'm trying to deploy a CMP entity bean and deployment fails with Error
creating table: ORA-02258. How do I avoid this?
You are getting this error because the table already exists in the data source
that is being used by your application and you have
autocreate-tables set to true
in your orion-application.xml.
This message will also be seen during a clustered application deployment since
the table is created by the first deployment and then during subsequent deployments
for the cluster, this message will be generated. This message is innocuous.
Top of Page
Entity Beans
-
Does OC4J support Oracle Application Server TopLink as Persistence
Manager for CMP entity beans?
No, OC4J currently does not support OracleAS TopLink CMP engine. The
current plan is that OC4J 10.0.3 will support OracleAS TopLink CMP engine.
However you can use OracleAS TopLink with BMP entity beans.
- How can I use a system generated primary key?
If you specify java.lang.Object
as the primary key class type in
<prim-key-class>, but do not specify the primary key name in
<primkey-field>, then the primary key is auto-generated by the
container. OC4J names the corresponding database column as autoid
by default.
- Can I use a database sequence for a primary key?
OC4J currently does not support a database sequence for primary key for
CMP entity beans. You have to use a stateless session bean or a Java class
to use a sequence to generate primary key for your CMP entity bean. The FAQ
demo application shipped with OC4J has an example of PK Generator using a
database sequence.
- Can I use a BLOB or CLOB field in a CMP entity bean?
OC4J does allow mapping of byte[] to BLOB and char[] or String to CLOB.
There is sample available in the How-To area of OC4J http://otn.oracle.com/tech/java/oc4j/htdocs/oc4j-how-to.html
- Does OC4J have support for additional data types such as Date, Time,
Timestamp, BigDecimal, etc. in EJBQL?
OC4J 9.0.4 supports these additional data types for EJB QL.
See the EJB Developer's Guide for more information.
- Does OC4J support Read Only patterns for entity beans?
Currently OC4J supports Read-only entity pattern only for CMP entity beans.
To mark your CMP as Read-only you have to set locking-mode="read-only"
in orion-ejb-jar.xml.
- What types of locking (pessimistic, optimistic or none) are provided
by the CMP Entity Bean provider implementation in OC4J?
OC4J, Release 9.0.2.x and above supports four locking modes including
optimistic, pessimistic, read-only, and old_pessimistic. These modes can be
combined with the isolation levels serializable and committed, to provide
a number of different strategies for concurrency.
Pessimistic: With this
locking mode, the container issues a "Select
for Update" to the database for any changes. This gives better
deadlock management and cluster support across OC4J instances since the
lock is deferred to the database. There are no data consistency issues and
there are no lost updates since the database manages the concurrency.
Optimistic: With the optimistic
locking mode, the container issues a "Select"
statement when the bean is loaded from the database and then performs an
update from the data in memory. If the isolation level is committed, then
it is possible to have a lost update problem since a change may be made
to the database between the time the data was selected and the change to
the database is issued. To ensure data consistency, use the serializable
isolation mode instead. (Note: serializable may have a performance impact.)
Read-only: The read-only
mode is provided for those beans that are being exposed and should not be
updated by the J2EE client. Attempts to perform and update are prevented
by the container and will raise an exception.
Old_pessimistic: This
mode is maintained for backward compatibility with OC4J 1.0.2.2 and for
use with
non-Oracle databases. This locking mode will be deprecated in future.
- How do I the O-R mapping for Entity beans using CMR?
You have to do the OR mapping in the
orion-ejb-jar.xml. Please see the Enterprise JavaBeans Developer's
guide for details. You can also use JDeveloper to generate these mappings.
The best trick to do mapping without using Oracle JDeveloper is to have OC4J
generate the default mapping based on provided ejb-jar.xml.
Modify the generated mapping from j2ee/home/application-deployments/<application
name>/<ejb-jar-name>/orion-ejb-jar.xml and include it with
your
<ejb-jar-name> file.
The attributes require modification are the
table-name and persistence-name.
- Does OC4J support 1-Many relationship with existing foreign key constraint?
Yes, OC4J supports 1-M relationship by either using foreign key or using
an intersection table.
- The relationship between my entities is dependent on a mandatory foreign
key and I'm getting foreign key constraint violation error during creation
of my entity. How do I resolve this?
The problem in the EJB specification is that it does not recognize existence
of mandatory foreign key constraints. Creation of entities is two step procedure
i.e. creation of entity in ejbCreate() and creation of relationship in ejbPostCreate().
In order to avoid this problem make the NOT NULL constraint DEFERRABLE in
your database so that the NOT NULL constraint is postponed until commit time.
Please see the EJB developers Guide for details. Future release of OC4J will
address this issue by providing an option to defer persistence of entity beans
to ejbPostCreate() method.
- Does OC4J support CMR with Composite PK with a mandatory foreign key?
Yes, OC4J supports CMR with composite primary key. There is sample available
in the How-To area of OC4J at http://otn.oracle.com/tech/java/oc4j/htdocs/oc4j-how-to.html.
- Is there any way to defer persistence of entity beans ejbPostCreate?
OC4J currently does not support deferred write for persisting CMP entity
beans. Future version of OC4J will address this issue.
- How do you bind a cmp-field attribute of an entity bean with a field
of an existing database table?
See CMP chapter of EJB Developer's Guide for details how to do the mapping.
- Can the primary key field of a CMP be a primitive type?
Yes it can be. What you need to do is specify which field is the primary
key (primkey-field tag) and
that the prim-key-class tag
represents the wrapper class for the primary key primitive type.
- Why does a CMP 1.1 Entity Bean CreateException not automatically rollback
all other operations in a transaction?
Per the EJB 1.1 specification, when the container receives this exception,
it will return it to the client and it is the client's responsibility to call
the setRollbackOnly() method to cause to transaction to roll back.
- I do not see ejbStore being called when I make changes to attributes
which are not persistent. Is there a way to force ejbStore to be called even
if I am not modifying persistent attributes?
By default, OC4J tries to prevent writing unchanged attributes to the
database. To force an update to occur, even if no changes have occurred, use
the force-update tag in orion-ejb-jar.xml
as shown below and redeploy your application. Redeployment is required since
wrapper generation is affected by setting this tag.
<orion-ejb-jar >
<enterprise-beans>
<entity-deployment name="MyBean" ... force-update="true">
...
</entity-deployment>
</enterprise-beans>
...
</orion-ejb-jar>
Top of Page
Session Beans
-
Does OC4J supports Stateful Session Beans passivation?
Yes OC4J 9.0.4 and above supports stateful session bean passivation.
Please see the EJB developers Guide for details.
- Does OC4J support pooling of stateless session beans?
Yes, OC4J supports pooling of stateless session beans. You can define
min-instances, max-instances, pool-cache-timeout,
etc for your session bean in the orion-ejb-jar.xml. For details please see
the EJB Developers Guide.
- Can I expose my stateless EJB as a web service in OC4J?
Yes OC4J supports exposing stateless EJB as a web service. For details
please look at the Webservices Developers Guide. Also you look at the web
services how-to at
http://otn.oracle.com/tech/java/oc4j/htdocs/how-to-ws-simple.html
Top of Page
Message Driven Beans
-
Is In-memory JMS supported with Message Driven Beans?
You can use the In-memory JMS with MDBs in OC4J 9.0.4. You can access
a sample application that demonstrates use of MDBs with OC4J JMS from
http://otn.oracle.com/sample_code/tech/java/ejb_corba/content.html
- Does OC4J support container managed transaction with MDBs ?
Yes. OC4J 9.0.3 and above support CMTs with MDBs.
- Can I use third-party JMS providers like MQ-Series or Sonic MQ with MDBs
in OC4J?
You can use OC4J with third-party JMS providers with MDBs deployed in
OC4J. However you have to remember that OC4J does not support recovery with
any third-party JMS providers in the event of failure.
Only transaction mode supported for MDBs used with third party providers is
NotSupported.
- How can I have multiple instances of a message bean, so that the messages
on the bean its listening location are processed in parallel?
You have to set listener-threads
to a number higher than 1 to have multiple instances of MDBs listening
to locations in parallel.
- What settings do I have to do for processing the messages by an MDB in
a particular order?
You have to set listener-threads
to 1 to if you want the messages must be processed in order.
- Re-deployment or shutdown of OC4J instances hangs while a Message Driven
Beans is listening to a Queue or Topic in OracleJMS?
This is primarily a problem in Windows environment due to a bug in the
OCI driver. You have to start OC4J with a system property
oracle.mdb.fastUndeploy=true in 9.0.3 and oracle.mdb.fastUndeploy
set to a number of seconds in OC4J 9.0.4 e.g.oracle.mdb.fastUndeploy=15
to avoid this problem.
The other alternative is to use the JDBC THIN driver.
- How can I change the transaction timeout for MDBs?
You can set the transaction-timeout
for your MDB in the orion-ejb-jar.xml.
Note that the server.xml timeout value, specified with transaction-config
timeout does not apply to MDBs. The default value for transaction-timeout
for MDBs is 86,400 seconds (1 day). When using OC4J
JMS, the transaction timeout cannot be altered from the default value.
- Is a MDB sample application available that uses OracleJMS based in Oracle
AQ?
Yes, you can access this sample from
http://otn.oracle.com/sample_code/tech/java/ejb_corba/content.html .
Top of Page
Transactions
-
What are the default transaction attributes in OC4J?
If you do not specify any transaction attributes for an EJB method then
OC4J uses default transaction attributes. OC4J by default uses Required
for CMP 2.0, NotSupported
for MDBs and Supports
for all other types of EJBs.
- How do I set the Transaction Isolation level for Container Managed Transactions
in OC4J? Which isolation levels are supported?
Transaction isolation levels are set in the orion-ejb-jar.xml
as an attribute of the entity-deployment
tag , e.g. <entity-deployment isolation="committed"
...>
The valid values for the isolation attribute are
serializable, uncommitted', committed and
repeatable_read.
The isolation modes supported are dependent on which isolation level(s)
are supported by the underlying data source. In the case of the Oracle8i
and Oracle9i databases, the supported isolation levels are
committed and serializable.
- Does the isolation level specified for OC4J transactions automatically
propagate to the underlying database transactions for CMP Entity Beans? Do
you have to manage this yourself for BMP Entity beans?
The isolation level needs to be propagated to the database by the container
and managed at the transaction level. In the OC4J Release 1.0.2.2, the setting
applies to the underlying JDBC connection and it is not reset at the transaction
boundary. With OC4J Release 1.0.2.2, using BMP and Select for Update, customers
can have better isolation control. This has been improved in OC4J release
9.0.2.0 and above.
- Does OC4J manage Two Phase Commit (2-pc) on the same container when the
EJBs are persisted in different databases?
OC4J 9.0.2 and above support for 2-PC is available. An Oracle database
is used as the commit coordinator to both coordinate and recover the transaction
in case of rollback. See the OC4J Services Guide for more information on 2-PC
configuration and operations.
- How does transaction context propagation work between EJBs that exist
on separate OC4J instances?
Transaction propagation is not currently supported across multiple instances
of OC4J.
- Is UserTransaction supported from application clients?
You cannot perform a client-demarcated transaction (begin .. method ...
commit) if the client is not in the same OC4J instance. If the client is running
in a
different Java virtual machine, then OC4J doesn't support client demarcated
transactions. If you use a servlet and demarcate a client transaction, then
the
corresponding EJB must exist in the same OC4J application.
- How do I mix connections that enlist with global transaction and
those that do not enlist with global transaction in an application?
Define 2 data sources, one JTA data source(emulated or non-emulated data
source) and a simple JDBC data source(ex: OracleDataSource
or OracleConnectionCacheImpl).
For connections that need to be enlisted with global transactions, use JTA
data source and for connections that do not need to be enlisted, use simple
JDBC data source
Below is an example:
JTA Emulated DataSource:
<data-source
class="com.evermind.sql.DriverManagerDataSource"
name="OracleDS"
location="jdbc/OracleCoreDS"
xa-location="jdbc/xa/OracleXADS"
ejb-location="jdbc/OracleDS"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="Scott"
password="tiger"
url="jdbc:oracle:thin:@localhost:5521:oracle"
inactivity-timeout="30"
/>
Simple JDBC datasource:
<data-source
class="oracle.jdbc.pool.OracleConnectionCacheImpl"
name="OracleDS2"
location="jdbc/OracleCoreDS2"
xa-location="jdbc/xa/OracleXADS2"
ejb-location="jdbc/OracleDS2"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="Scott"
password="tiger"
url="jdbc:oracle:thin:@localhost:5521:oracle"
inactivity-timeout="30"
/>
Following code snippet demonstrates how to achieve this :
jtaDS=ic.lookup("jdbc/OracleDS);
simpleDS = ic.lookup("jdbc/OracleDS2);
...
ut.begin();
enlistedConn = jtaDS.getConnection();
nonEnlistedConn = simpleDS.getConnection();
- Is two phase commit supported between OracleJMS and another Oracle database?
Yes, two phase commit is supported using the OracleJMS implementation.
In addition, if the OracleJMS queues reside on the same server, optimizations
may be made to perform a single phase commit.
- Is two phase commit supported between third party JMS providers or databases?
OC4J currently does not provide recovery protocol in two-phase commit
scenario while using third party JMS providers or non-Oracle databases. OC4J
10.0.3 will fully support two-phase commit protocol with third party databases
and JMS providers.
Top of Page
Performance Tuning
-
Where can I get information about tuning performance of EJB applications?
The Oracle Application Server Performance Guide has a section that contains
information relating to performance monitoring and tuning of EJB applications.
Documentation for all Oracle products is available from the Oracle Technology
Network (OTN) at http://otn.oracle.com/documentation/content.html.
The Performance Guide is available with the platform specific documentation
for Oracle Application Server.
-
I am receiving the following exception "com.evermind.server.ejb.TimeoutExpiredException:
timeout expired waiting for an instance" What might be the cause?
This occurs when there is no available EJB instance in the EJB pool.
To avoid this problem set the max-instances parameter appropriately. You
can set
the max-instances to appropriate value or unlimited by setting this to 0
in the orion-ejb-jar.xml.
Starting with OC4J 9.0.4 this is set to 0 (unlimited) by default.
<orion-ejb-jar >
<enterprise-beans>
<entity-deployment name="MyBean" .. max-instances="0">
...
</entity-deployment>
</enterprise-beans>
...
</orion-ejb-jar>
-
I have a an EJB application that runs for some period of time and starts
receiving Out of Memory - No Stack Trace Available" message. How can
I prevent OC4J from running out of memory?
Edit the orion-ejb-jar.xml file in the
$OC4J_HOME/application-deployments/$YOUR_PROJECT$-ejb.jar directory.
Set the attribute max-instances='x'
in all the EJBs deployed, where code> x is the maximum number
of EJBs you allow in memory at any time. This prevents your system from
running out of memory.
The following is a sample line (taken from the orion-ejb-jar.xml
file):
<entity-deployment name="ForumMessageEJB"
location="ForumMessageEJB"
wrapper="ForumMessageHome_EntityHomeWrapper23"
max-instances="10"
table="ForumMessageEJB">
<ejb-ref-mapping name="ejb/forummessage" />
<resource-ref-mapping name="jdbc/biltmart" />
</entity-deployment>
- OC4J executes an extra SELECT
statement during creation of entity beans to check duplicate primary key and
that degrades the performance. How do I avoid this extra select statement?
You have to set do-select-before
insert to false in the
orion-ejb-jar.xml (default
is true) for your EJB in the entity-deployment
section for your CMP entity bean.
- My finder method returns a large number of rows. Is there anyway I can
improve the performance by reducing the round trips to database?
Oracle JDBC driver has extensions that allows setting the number of rows
to pre-fetch into the client while a result set is being populated during
a query, reducing the number of round trips to the server. This can drastically
improve performance of finder methods that returns large number of rows by
reducing the number of round trips. You can specify the prefetch-size for
your finder method in the orion-ejb-jar.xml
as follows:
<finder-method query="" prefetch-size="15"
>
For details, see the EJB Developer's Guide.
- What is lazy loading and is this turned on by default?
If you turn on lazy loading, then only the primary keys of the objects
retrieved when the finder methods are returned. Then, only when you access
the object within your implementation, the EJB container uploads the actual
object based on the primary key. In 9.0.3, lazy-loading is turned on by default
and in 9.0.4 this turned off by default.
If you retrieve multiple objects, but you only use a few of them, then
you should turn on lazy loading. In addition, if you only use objects through
the getPrimaryKey method,
then you should also turn on lazy loading. To turn on lazy loading in the
findByPrimaryKey method, set the findByPrimaryKey-lazy-loading attribute
to true, as follows: <entity-deployment ... findByPrimaryKey-lazy-loading="true"
... >
To turn on lazy loading in any custom finder method, set the lazy-loading
attribute to true in the <finder-method>
element for that custom finder, as follows:
<finder-method ... lazy-loading="true" ...>
- How do enable SQL statement caching?
You can cache database statements, which prevents the overhead of repeated
cursor creation and repeated statement parsing and creation. In the DataSource
configuration, you enable JDBC statement caching, which caches executable
statements that are used repeatedly. The following XML sets the statement
cache size to 200 statements in your data-sources.xml
file.
<data-source>
...
stmt-cache-size="200"
</datasource>
- How can I change the transaction timeout for EJBs?
You can change the default value for the transaction configuration timeout
in the transaction-config element in the server.xml
file for the OC4J instance. The transaction-config
timeout is not an EJB specific timeout, but affects all transactions
that use EJBs except MDBs. The default value for this parameter is 60000 milliseconds
(60 seconds).
For example, the following server.xml sets the transaction-config timeout
parameter to 30 seconds:
<transaction-config timeout="30000"/>
- When some of my EJB method fails it seems to retry three times. How can
I change this behavior?
For OC4J 9.0.3 and prior the default value for max-tx-retries
is 3 and hence in the event of a failure of a method call the method is retried
three times. You can set max-tx-retries
to 0 to change this behavior. In 9.0.4 the default value for max-tx-retries
is reset to 0.
- How do I set the container to include all fields in the update statement?
You can set update-changed-fields-only
to false for your CMP
entity beans in the orion-ejb-jar.xml
and this makes container updates all fields to persistence storage
for CMP entity beans when ejbStore is invoked.
Top of Page
Clustering and Load balancing
-
What types of EJBs can I cluster?
Only Stateful Session Beans can be clustered for session replication
and recovery. OC4J provides load balancing for all other EJBs.
- What types of replication modes are supported for EJB clustering?
OC4J supports VMTermination and EndOfCall replication modes for replicating
states. See Enterprise JavaBeans Developer's guide for details.
- Can I use EJB clustering over both the ORMI and RMI-IIOP protocol?
The session state replication (end-of-call, VM termination, etc) occurs
independent of an EJB being accessed by an RMI-IIOP client but the RMI-IIOP
client will not failover or load balance.
- Is there a step-by-step how-to to configure EJB clustering using OC4J
standalone instances?
Yes, there is a How-To available at http://otn.oracle.com/tech/java/oc4j/htdocs/oc4j-how-to.html.
- What algorithm OC4J support for load balancing for ORMI?
OC4J uses a random algorithm for load balancing ORMI requests.
- What are my options for load balancing ORMI requests ?
You can use either of the following options:
- DNS Load balancing
- Load balancing using dynamic retrieval
- Load balancing using static retrieval
See the Enterprise JavaBeans Developer's guide for details.
- How do you do load balancing using dynamic retrieval?
The JNDI addresses of all OC4J nodes that can be contacted for load balancing
and failover are dynamically discovered during the first JNDI lookup. The
client must perform a lookup with a "lookup:" prefix, as follows:
ic.lookup("lookup:ormi://s1:23971/ejbsamples");
- How do I use
LoadBalanceOnLookup ?
The client retrieves a random OC4J process when the first lookup is executed.
The selection of which OC4J process that services the client is always randomly
chosen
from among the pooled OC4J processes in the cluster. If you set LoadBalanceOnLookup
property set to true, then the client randomly picks another OC4J process
from the pooled processes in the cluster each time a lookup is executed. You
can only use RMIInitialContextFactory
when using LoadBalanceOnLookup.
The following code snippet provides how to use this lookup:
env.put("LoadBalanceOnLookup", "true");
- How do you perform Load balancing using static retrieval?
If you want to load balance the request across several OC4J processes,
you can use static retrieval by providing the URLs
for all of these processes in the JNDI URL property. You can use static retrieval
only when you know the RMI ports for the OC4J instances. For example, the
following URL definition provides the client container with three OC4J nodes
to use for load balancing and failover.
java.naming.provider.url=ormi://s1:23791/ejbsamples,ormi://s2:23793/ejbsamples,
ormi://s3:23791/ejbsamples;
- Dynamic discovery of nodes is not working for my cluster of standalone
OC4J instances. What may be wrong?
The host attribute in the
rmi-server tag in rmi.xml
is mandatory for EJB clustering to work. Please make sure that you have this
for all your OC4J instances as follows:
<RMI-server host="hostname" port="23791" >
Top of Page
Security
- What are the permissions need to be executed when EJB is looked up by
an applet ?
If you download an applet that looks an EJB application as a client and
the security manager is active, you must grant the following permissions before
you can execute:
permission java.net.SocketPermission "*:*", "connect,resolve";
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "getClassLoader";
permission java.util.PropertyPermission "*", "read";
permission java.util.PropertyPermission "LoadBalanceOnLookup",
"read,write";
- Can I lookup an EJB without specifying principal and credential?
OC4J currently does not support lookup of unchecked EJB without specifying
principal and credential.
- How do I specify an unchecked security for EJB methods?
If you want certain methods to not be checked for security roles, you
define these methods as unchecked, as follows:
<method-permission>
<unchecked/>
<method>
<ejb-name>EJBNAME</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
- Where do I map Roles to Users and Groups?
You can use logical roles or actual users and groups in the EJB deployment
descriptor. However, if you use logical roles, you must map them to the actual
users and groups defined either in the JAZN or XML User Managers in the orion-ejb-jar.xml.
For example maps the logical role POMGR to the managers group in the orion-ejb-jar.xml
file.
<security-role-mapping name="POMGR">
<group name="managers" />
</security-role-mapping>
-
Does OC4J support security context propagation between EJBs deployed
in different OC4J instances using ORMI?
No. OC4J does not support security context propagation between OC4J
instances.
Top of Page
Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065
U.S.A.
Worldwide Inquiries:
+1.650.506.7000
Fax +1.650.506.7200
http://www.oracle.com/
Copyright © Oracle Corporation
2003
All Rights Reserved
This document is provided for
informational purposes only,
and the information herein is
subject to change
without notice. Please
report any errors herein to
Oracle Corporation. Oracle
Corporation does not provide
any warranties covering and specifically
disclaims any
liability in connection with
this document.
Oracle is a registered trademark
of Oracle Corporation.
All other company and product
names mentioned are used
for identification purposes only
and may be trademarks of
their respective owners.
|