Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

EJB 3.0 Support

In this release, OC4J supports all but a small subset of the functionality specified in the final EJB 3.0 specification (http://jcp.org/aboutJava/communityprocess/pr/jsr220/index.html).

You may need to make minor code changes to your EJB 3.0 OC4J application after OC4J is updated to full EJB 3.0 compliance. For more information, see "Migrating a 10.1.3.0 TopLink JPA Preview Application to 10.1.3.1 TopLink Essentials JPA".

In this release, OC4J supports the use of annotations, standard deployment XML (ejb-jar.xml or orion-ejb-jar.xml), or both for all EJB 3.0 features except for the object-relational entity mapping types (namely basic, binary large object (LOB), serialized, one-to-one, many-to-one, one-to-many, many-to-many, and aggregate mappings). For these, you must either use annotations or TopLink JPA persistence provider customization.

OC4J supports the proprietary EJB 3.0 annotations that the Oracle Application Server Annotations API Reference describes.

For more information, see:

In this release, OC4J supports resource injection in the Web tier. For more information, see "Annotations in the Web Tier".

This section describes the following:

What JDK is Required?

By default, if you are using EJB 3.0, then you must use JDK 1.5. By default, OC4J does not support the use of EJB 3.0 and JDK 1.4.

OC4J supports the use of EJB 3.0 (excluding annotations and interceptors) with JDK 1.4 only with the TopLink JPA preview persistence provider. For more information, see the discussion of system property default.persistence.provider in "JPA Persistence JAR Files".

How do You Define an EJB 3.0 Application?

For entities, OC4J assumes that the application is an EJB 3.0 application, if an EJB JAR is deployed without an ejb-jar.xml file. For more information, see "Understanding EJB Persistence Services"

For session beans and message-driven beans, OC4J assumes that the application is an EJB 3.0 application if the ejb-jar.xml file <ejb-jar> element version attribute is set to 3.0.

How Does OC4J Manage Persistence in an EJB 3.0 Application?

In an EJB 3.0 application, OC4J delegates persistence operations to a JPA persistence provider: in this release, OC4J uses TopLink Essentials, the JPA persistence provider for the EJB 3.0 Reference Implementation (see "TopLink Essentials JPA Persistence Provider").

TopLink Essentials JPA Persistence Provider

Oracle TopLink is an advanced, object-persistence and object-transformation framework that provides development tools and run-time capabilities that reduce development and maintenance efforts, and increase enterprise application functionality.

In this release, OC4J manages EJB 3.0 entities using TopLink Essentials, the JPA persistence provider for the EJB 3.0 Reference Implementation. For more information, see "What is TopLink?" in the Oracle TopLink Developer's Guide.

OC4J provides JAR files for both the classes that the EJB 3.0 persistence specification mandates and the classes that make up the TopLink Essentials JPA persistence provider implementation. For more information about persistence JAR files, see "JPA Persistence JAR Files".

For EJB 3.0 projects, you configure persistence properties through annotations or persistence.xml file. OC4J translates this metadata into TopLink configuration. For more information on customizing the TopLink Essentials EJB 3.0 JPA persistence provider, see "Customizing the JPA Persistence Provider".

JPA Persistence JAR Files

OC4J uses the JAR files that Table 3-1 lists to provide the TopLink Essentials JPA persistence provider implementation. These JAR files are located in the <ORACLE_HOME>/toplink/jlib directory.

The system property default.persistence.provider determines which JPA persistence provider implementation OC4J uses. The following are valid values:

  • essentials (default): OC4J uses the <ORACLE_HOME>/j2ee/home/lib/persistence.jar to provide EJB 3.0 JPA classes that the EJB 3.0 persistence specification mandates and <ORACLE_HOME>/toplink/jlib/toplink-essentials.jar and toplink-essentials-agent.jar for the persistence provider implementation, providing full support for the final EJB 3.0 persistence specification.

  • toplink: OC4J uses the <ORACLE_HOME>/j2ee/home/lib/preview-persistence.jar to provide EJB 3.0 JPA classes that the public review EJB 3.0 persistence specification mandated and <ORACLE_HOME>/toplink/jlib/toplink.jar as the persistence provider implementation, providing a JPA preview based on a subset of the functionality specified in the EJB 3.0 public review draft. You can use this option to run an application written to the preview API. Oracle does not recommend that you use this option.

Table 3-1 TopLink JAR Files

JAR File Contents

antlr.jar

This JAR file contains the Antlr (ANother Tool for Language Recognition) tool.

toplink.jar

This JAR file contains all the classes that comprise the TopLink API, including classes with Oracle JDBC dependencies.

If you want to use an Oracle JDBC driver version different than the default version installed with OC4J, see "Associating TopLink With an Oracle JDBC Driver".

toplink-essentials.jar

This JAR file contains the open source JPA edition of TopLink, the JPA persistence provider for the EJB 3.0 Reference Implementation.

toplink-essentials-agent.jar

This JAR file contains the classes that TopLink uses to perform byte-code weaving on JPA entities to automatically enable features such as ValueHolder indirection. You invoke toplink-essentials-agent.jar by adding -javaagent:toplink-essentials-agent.jar to your client JVM command line or by using the toplink.weaving TopLink JPA extension that you can define in a persistence.xml file. This option is not necessary on the server JVM command line.

This JAR file provides part of TopLink Essentials, the JPA persistence provider for the EJB 3.0 Reference Implementation. It is used with toplink-essentials.jar.

This JAR is optional. It should never be placed on the classpath and should only be used as part of -javaagent.

toplink-oc4j.jar

This JAR contains the classes that TopLink uses to integrate with Oracle Containers for J2EE.

This JAR file is only used in OC4J; the container is preconfigured to use toplink-oc4j.jar. In a non-OC4J application, use toplink.jar.


Customizing the JPA Persistence Provider

Typically, you use object-relational annotations (see "Configuring a Container-Managed Relationship Field for a JPA Entity") to specify how you want OC4J to store a persistent field in the database and rely on the default TopLink EJB 3.0 JPA persistence provider configuration for each such annotation. However, you may wish to override this default behavior to suit your application requirements. As well, although the TopLink EJB 3.0 JPA persistence provider is JPA compliant, it provides additional extensions beyond what is defined in the JPA specification.

You may customize the OC4J JPA persistence provider in any of the following ways:

Accessing TopLink API at Run Time With TopLink Essentials JPA Persistence

If you are using the TopLink Essentials JPA persistence provider (default), you access TopLink API in a JPA entity application at run time by using TopLink JPA extensions toplink.session.customizer and toplink.descriptor.customizer.<ENTITY> (see Table 26-5).

Accessing TopLink API at Run Time With TopLink JPA Preview Persistence

If you are using the TopLink JPA preview persistence provider, you access the TopLink API in a JPA entity application at run time by creating an ejb3-toplink-sessions.xml file (see "What is the ejb3-toplink-sessions.xml File?") and toplink-ejb-jar.xml (see "What is the toplink-ejb-jar.xml File?") file.

Note:

By default, OC4J uses the TopLink Essentials JPA persistence provider. In this case, you access TopLink API in a JPA entity application at run time by using TopLink JPA extensions (see "Accessing TopLink API at Run Time With TopLink Essentials JPA Persistence").

You package these files in the META-INF directory of the EJB-JAR that contains your EJB 3.0 entities.

  • To customize TopLink session-level options, you only need an ejb3-toplink-sessions.xml file.

  • To customize TopLink persistence-specific options, you need both an ejb3-toplink-sessions.xml and toplink-ejb-jar.xml file.

You can use the TopLink API to customize persistence by overriding annotations or by replacing annotations altogether. For example, you might use annotations for most of your object-relational mappings and an ejb3-toplink-sessions.xml and toplink-ejb-jar.xml file to specify object-relational mappings for a subset of complex relationships not suited to annotation.

If the only JDK 1.5 language extension that your entity classes use are annotations, you can use the TopLink Workbench to create and configure these files. Oracle recommends using the TopLink Workbench to create and configure these files.

To customize the TopLink JPA preview persistence provider, do the following:

  1. Create a relational TopLink Workbench project (see "Creating a Project" in the Oracle TopLink Developer's Guide).

  2. Configure the TopLink Workbench project classpath to include your JDK 1.5 compiled entity classes (see "Configuring Project Classpath" in the Oracle TopLink Developer's Guide).

  3. Configure the project deployment XML file name (as toplink-ejb-jar.xml) and save location (see "Configuring Project Deployment XML Options" in the Oracle TopLink Developer's Guide).

  4. Optionally, configure other TopLink project-level options (see "Configuring a Relational Project" in the Oracle TopLink Developer's Guide).

  5. Configure TopLink relational descriptors for the entity classes you want to customize (see "Creating a Relational Descriptor" in the Oracle TopLink Developer's Guide and "Configuring a Relational Descriptor" in the Oracle TopLink Developer's Guide).

  6. Configure TopLink relational mappings for the persistent fields you want to customize (see "Creating a Mapping" in the Oracle TopLink Developer's Guide and "Configuring a Relational Mapping" in the Oracle TopLink Developer's Guide).

  7. Export your TopLink Workbench project to the toplink-ejb-jar.xml XML file (see "Exporting Deployment XML Information" in the Oracle TopLink Developer's Guide).

  8. Create a TopLink sessions configuration file named ejb3-toplink-sessions.xml (see "Creating a Server Session" in the Oracle TopLink Developer's Guide).

  9. Set the ejb3-toplink-sessions.xml file primary project to your toplink-ejb-jar.xml file (see "Configuring a Primary Mapping Project" in the Oracle TopLink Developer's Guide).

  10. Optionally, configure any other TopLink session-level options (see "Configuring a Server Session" in the Oracle TopLink Developer's Guide).

  11. Save your TopLink Workbench sessions configuration file.

  12. Package the ejb3-toplink-sessions.xml and toplink-ejb-jar.xml file in the META-INF directory of the EJB-JAR that contains your EJB 3.0 entities.

Note:

Alternatively, you can use JDeveloper to create the ejb3-toplink-sessions.xml and toplink-ejb-jar.xml file (see "Using EJB Development Tools".).

Migrating a 10.1.3.0 TopLink JPA Preview Application to 10.1.3.1 TopLink Essentials JPA

In 10.1.3.0 release, OC4J uses the TopLink JPA preview persistence provider based on a subset of the functionality specified in the EJB 3.0 public review draft.

In 10.1.3.1 release, OC4J uses the TopLink Essentials JPA persistence provider, the JPA persistence provider for the EJB 3.0 Reference Implementation, to provide full JPA support according to the final EJB 3.0 specification.

You must make code changes to your JPA preview-based application before using it with TopLink Essentials and the final EJB 3.0 API in OC4J 10.1.3.1.

In general, you should do the following:

  1. Undeploy your preview-based application.

  2. Upgrade OC4J from 10.1.3.0 to 10.1.3.1.

  3. Make the necessary post-upgrade configuration file changes (see "Changes in OC4J Configuration Files").

  4. Migrate your code to use the new EJB 3.0 API.

    The following sections describe the important differences between the TopLink JPA preview and full TopLink JPA to help you identify where changes must be made:

  5. Redeploy your updated application.

Changes in OC4J Configuration Files

After applying the 10.1.3.1.0 patch set to a 10.1.3.0.0 OC4J, you must manually edit OC4J configuration files as follows:

  1. Edit the <ORACLE_HOME>/j2ee/home/config/server.xml file and add the following:

    <shared-library name="oracle.persistence" version="1.0" library-compatible="true">
        <code-source path="../../../toplink/jlib/toplink-essentials.jar"/>
    </shared-library>
    
  2. Edit the <ORACLE_HOME>/j2ee/home/config/system-application.xml file and add the following to the <imported-shared-libraries> element:

    <import-shared-library name="oracle.persistence"/>
    

Changes in javax.persistence

Table 3-2 lists the additions, deletions, and changes made to the javax.persistence package between 10.1.3.0 and 10.1.3.1. If your application uses any of these classes, consult the latest EBJ 3.0 specification and JPA Javadoc for details.

Table 3-2 Changes to javax.persistence

10.1.3.0 10.1.3.1 Description

AccessMode

deleted

In 10.1.3.1 release, EJB 3.0 entities do not require local or remote interfaces. Because all entity access is by way of an EntityManager, clients need not be concerned about whether access is local or remote.

AccessType

deleted

In 10.1.3.1 release, the EJB 3.0 persistence specification requires the use of a single access type in an entity hierarchy. The placement of the mapping annotations determines the access type in effect.

N/A

AssociationOverride

Added in 10.1.3.1 release as part of the changes made to annotations for inheritance.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#AssociationOverride.

N/A

AssociationOverrides

Added in 10.1.3.1 release as part of the changes made to annotations for inheritance.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#AssociationOverrides.

Basic

Basic

In 10.1.3.1 release, attribute temporalType is omitted.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#Basic.

N/A

DiscriminatorValue

Added in 10.1.3.1 release as part of the changes made to annotations for inheritance.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#InheritanceAnnotations

EmbeddableSuperclass

deleted

Added in 10.1.3.1 release as part of the changes made to annotations for inheritance.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#InheritanceAnnotations

Entity

Entity

In 10.1.3.1 release, attribute access is omitted.

N/A

EntityExistsException

Added in 10.1.3.1 release.

EntityListener

deleted

In 10.1.3.1 release, use EntityListners instead.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#EntityListeners.

N/A

EntityListeners

Added in 10.1.3.1 release.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#EntityListeners.

EntityManager

EntityManager

In 10.1.3.1 release, EntityManager method getUserTransaction is named getTransaction.

New methods added in 10.1.3.1 include the following:

  • setFlushMode

  • getFlushMode

  • lock

  • clear

  • joinTransaction

  • getDelegate

In 10.1.3.1 release, methods of this class throw additional exceptions such as EntityExistsException and IllegalStateException, and, in some cases, methods throw IllegalStateException instead of IllegalArgumentException.

EntityNotFoundException

EntityNotFoundException

In 10.1.3.1 release, this exception extends PersistenceException instead of RuntimeException.

EntityTransaction

EntityTransaction

New methods added in 10.1.3.1 release include the following:

  • setRollbackOnly

  • getRollbackOnly

EntityType

deleted

In 10.1.3.1 release, the EJB 3.0 specification removes the concept of BMP.

To develop and deploy a Java EE 5 BMP application, you must use the EJB 2.1 API.

N/A

Enumerated

Added in 10.1.3.1 release to support direct mappings of enumerated types.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#Enumerated.

N/A

EnumType

Added in 10.1.3.1 release to support direct mappings of enumerated types.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#Enumerated.

N/A

ExcludeDefaultListeners

Added in 10.1.3.1 release to support managing life cycle callback default listeners.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#ExcludeDefaultListeners.

N/A

ExcludeSuperclassListeners

Added in 10.1.3.1 release to support managing life cycle callback superclass listeners.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#ExcludeSuperclassListeners.

FlushMode

deleted

In 10.1.3.1 release, to set the flush mode, use the EntityManager method setFlushMode to set the FlushModeType.

N/A

GeneratedValue

Added in 10.1.3.1 release to support automatic primary key (identity) generation.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#GeneratedValue.

N/A

GenerationType

Added in 10.1.3.1 release to support automatic primary key (identity) generation.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#GeneratedValue.

GeneratorType

deleted

In 10.1.3.1 release, use GeneratedValue attribute strategy to set the GenerationType.

Inhertiance

Inheritance

In 10.1.3.1 release, the following attributes are omitted:

  • discriminatorType

  • discriminatorValue

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#InheritanceAnnotations.

JoinColumn

JoinColumn

In 10.1.3.1 release, attribute secondaryTable is changed to table.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#JoinColumn.

JoinTable

JoinTable

In 10.1.3.1 release, attribute table (type Table) is changed to name (type String).

The following attributes are added:

  • catalog

  • schema

  • uniqueConstraints

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#JoinTable.

LobType

deleted

In 10.1.3.1 release, use direct mapping annotation @Lob to specify a Lob type. A Lob may be either a binary or character type. The persistence provider infers the Lob type from the type of the persistent field or property.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#Lob.

N/A

LockModeType

Added in 10.1.3.1 release.

N/A

MappedSuperclass

Added in 10.1.3.1 release as part of the changes made to annotations for inheritance.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#MappedSuperclass.

NamedNativeQuery

NamedNativeQuery

In 10.1.3.1 release, attribute queryString changed to query and attribute hints was added.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#NamedNativeQuery.

NamedQuery

NamedQuery

In 10.1.3.1 release, attribute queryString changed to query and attribute hints was added.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#NamedQuery.

NoResultException

NoResultException

In 10.1.3.1 release, this exception extends PersistenceException instead of RuntimeException.

N/A

OptimisticLockException

Added in 10.1.3.1 release.

PersistenceContext

PersistenceContext

In 10.1.3.1 release, attribute properties was added.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#PersistenceContext.

N/A

PersistenceProperty

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#PersistenceProperty.

N/A

QueryHint

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#QueryHint.

N/A

RollbackException

Added in 10.1.3.1 release.

SecondaryTable

SecondaryTable

In 10.1.3.1 release, attribute pkJoin was changed to pkJoinColumns.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SecondaryTable.

SequenceGenerator

SequenceGenerator

In 10.1.3.1 release, the default for attribute initialValue changed from 0 to 1.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SequenceGenerator.

N/A

SqlResultSetMappings

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SqlResultSetMappings.

Table

Table

In 10.1.3.1 release, attribute specified is omitted.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#Table.

TableGenerator

TableGenerator

In 10.1.3.1 release, the following attributes were added:

  • catalog

  • schema

  • uniqueConstraints

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#TableGenerator.

N/A

Temporal

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#Temporal.

TemporalType

TemporalType

In 10.1.3.1 release, enum value NONE is omitted.

For more information, see http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#Temporal.

TransactionRequiredException

TransactionRequiredException

In 10.1.3.1 release, this exception extends PersistenceException instead of RuntimeException.


Changes in oracle.toplink.essentials.platform.database

In 10.1.3.1 release, the following new classes were added:

  • DerbyPlatform

  • JavaDBPlatform

  • PostgreSQLPlatform

Changes in Interceptor Support

If you are using TopLink JPA with OC4J, be aware of the fact that interceptors changed substantially between the TopLink JPA preview and the final EJB 3.0 specification.

In the final EJB 3.0 specification, interceptors and life cycle event listeners are merged and both use javax.interceptors.Interceptors. This will affect any code that uses interceptors or life cycle event listeners, in particular session beans and message-driven beans.

For more information, see the following:

Acquiring an Entity Manager

In 10.1.3.0 release, you use the java.persistence.setup.config property to identify a class with the list of entities that an entity manager manages.

In 10.1.3.1 release, this property is obsolete. Instead, you must define managed entity classes in a persistence unit as specified in the EJB 3.0 specification.

In 10.1.3.0 release, you inject an entity manager using the @Resource annotation.

In 10.1.3.1 release, you inject an entity manager using the @PersistenceContext annotation:

@PersistenceContext protected EntityManager entityManager;

In 10.1.3.1 release, OC4J supports the use of @Resource to inject an entity manager for backward compatibility. However, Oracle recommends that you use the @PersistenceContext annotation instead to be compliant with the EJB 3.0 specification.

For more information, see the following:

New JAR Files

In 10.1.3.0 release, OC4J uses the persistence-preview.jar and toplink.jar file to provide the JPA preview implementation.

In 10.1.3.1 release, OC4J uses the persistence.jar and the toplink-essentials.jar and toplink-essentials-agent.jar files to provide the full JPA implementation.

In your IDE, ensure that any library definitions you may have associated with your projects include only the 10.1.3.1 JPA libraries and exclude the old 10.1.3.0 libraries.

For more information about TopLink JAR files, see "JPA Persistence JAR Files".