EJB 3.0 Database Persistence with Oracle Fusion Middleware 11g
EJB (Enterprise JavaBeans) 3.0 entity beans is a commonly used database persistence
technology. EJB 3.0 has simplified the development of EJBs with an annotations-based
APithat does not require remote/local interfaces, home/local home interfaces, or
deployment descriptors. Developing entity EJBs requires an application server and a
relational database, and optionally a Java EE IDE to simplify the process of development.
The objective of the JSR-000220 Enterprise JavaBeans 3.0 specification (
is to improve the EJB architecture by reducing its complexity from the developer’s point
of view. EJB 3.0 has introduced some new features, which include support for metadata
annotations, default values for configuration, simplified access to environment variables,
simplified session and entity beans, interceptors, enhanced support for checked
exceptions, and elimination of callback interfaces.
A number of books are available on EJB 3.0, but none cover EJB 3.0 on the Oracle
Fusion Middleware (11g) platform. Most of the EJB 3.0 books are GlassFish server
based, which has only 10percent of the application server market. Welcome to EJB 3.0
Database Persistence with Oracle Fusion Middleware 11g, a book that will teach you
how to leverage EJB 3.0 persistence on Oracle Fusion Middleware 11g. Oracle Fusion
Middleware 11g includes many components such as the SOA/BPM Suite, WebCenter,
and Oracle Identity Management. All of these components run on Oracle Weblogic
Server 11g. The main development tool (IDE) for Oracle Fusion Middleware is Oracle
JDeveloper. In respect of EJB 3.0, JDeveloper provides wizard support to reverse
engineer database tables as EJB 3.0 entity beans. JDeveloper 11g also provides a wizard
for creating session beans. The JPA persistence provider used in JDeveloper 11g is the
EclipseLink persistence provider. JDeveloper comes with its own embedded/integrated
Weblogic Server instance, which makes it very easy to develop and test within the one
environment. We shall be using the embedded WebLogic Server 11g in some of the
chapters and the standalone WebLogic Server in others.
The objective of the book is to discuss the support of EJB 3.0 database persistence in
Oracle Fusion Middleware 11g. While JDeveloper is the main Java IDE used in the book,
one of the chapters leverages the Oracle Enterprise Pack for Eclipse. The book covers all
aspects of EJB 3.0 database persistence including:
- Creating EJB 3.0 entity beans from database tables
- Creating session bean façades for entity beans
- Entity beans with session beans
- Creating EJB 3.0 entity relationships
- Creating JSF and ADF Faces user interfaces (UIs) on top of EJB 3.0
- Using EJB 3.0 database persistence in combination with Ajax and web services
EJB 3.0 Articles
- JPA in NetBeans 6.1
- EJB 3.0 and WebServices
- Introduction to Java Persistence API(JPA)
- EJB 3.0 Timer Services – An Overview
What This Book Covers
In Chapter 1, What’s New in EJB 3.0, we discuss the new features in the EJB 3.0
specification, such as support for metadata annotations, default values for configuration,
simplified session and entity beans, and enhanced support for checked exceptions.
In Chapter 2, Converting an EJB 2.0 Entity to an EJB, we convert an example EJB 2.0
entity bean to an EJB 3.0 entity bean. We also generate the session bean façade for the
EJB 3.0 entity bean. XSLT transformation is used for converting the EJB 2.0 entity bean
to an EJB 3.0 entity bean.
In Chapter 3, EclipseLink JPA Persistence Provider, we discuss the JPA framework and
the EclipseLink persistence provider.
In Chapter 4, Building an EJB 3.0 Persistence Model with Oracle JDeveloper, we discuss
EJB 3.0 database persistence with JDeveloper 11g, WebLogic Server 11g, and Oracle
Database 10g. We create an EJB 3.0 entity bean from a database table, create a session
bean façade, and finally create a JSP test client. Using the test client, we create, retrieve,
and delete entity bean instances.
In Chapter 5, EJB 3.0 Persistence with Oracle Enterprise Pack for Eclipse, we discuss the
same example we covered in Chapter 4, but with the Oracle Enterprise Pack for Eclipse,
WebLogic Server, and the open source MySQL database, which has been acquired by
In Chapter 6, EJB 3.0 with ADF Faces UI, we discuss using an ADF Faces client for EJB
3.0 database persistence. We create an entity bean using data input from an ADF Faces
user interface (UI). Subsequently, we find an entity bean instance using data input from
an ADF Faces UI.
In Chapter 7, Creating EJB 3.0 Entity Relationships, we discuss EJB 3.0 entity
relationships using, as an example, three entity beans that have inter-relationships. We
also discuss the significance of a fetch strategy.
In Chapter 8, EJB 3.0 Database Persistence with Ajax in the UI, we discuss EJB 3.0
database persistence in combination with Ajax in the user interface (UI). We demonstrate
data validation and autocompletion with Ajax.
In Chapter 9, Using JSF with Entity Relationships, we discuss adding JSFs to EJB 3.0
database persistence to create and persist entity bean instances that have entity
relationships between them.
In Chapter 10, Creating an EJB 3.0 Web Service, we create a JAX-WS Web Service from
an EJB 3.0 entity bean, create a web service client, package and deploy the web service
to WebLogic Server, and test the Web Service using the WebLogic console.
Building an EJB 3.0 Persistence Model with Oracle JDeveloper
Oracle Fusion Middleware is a family name for a set of Java EE products that are
integrated for SOA and web application deployment. WebLogic Server (WLS) is the
Java EE container and Oracle JDeveloper the Java EE and SOA development IDE.
In this chapter, we will use JDeveloper to create an EJB 3.0 application, and then we
will deploy and test our application leveraging the embedded WebLogic Server that
comes with JDeveloper. This makes it very easy for us to develop, deploy, and test
WebLogic server 10.x provides some value-added features to facilitate EJB
3 development. WebLogic server 10.x supports automatic deployment of a
persistence unit based on the injected variable’s name. The @javax.persistence.
PersistenceContext and @javax.persistence.PersistenceUnit
annotation s are used to inject the persistence context in an EntityManager or
EntityManagerFactory variable . A persistence context is a set of entities that are
mapped to a database with a global JNDiname. If the name of the injected variable
is the same as the persistence unit, the unitName attribute of the
@PersistenceContext or @PersistenceUnit is not required to be specified. The
EJB container automatically deploys the persistence unit and sets its JNDiname to
be the same as the persistence unit name in persistence.xml. For example, if the
persistence unit name in the persistence.xml file is em, an EntityManager variable
may be injected with the persistence context as follows:
private EntityManager em;
We did not need to specify the unitName attribute in the @PersistenceContext
because the variable name is the same as the persistence unit. Similarly, an
EntityManagerFactory variable may be injected with the persistence context as
follows, emf being also the persistence unit name:
private EntityManagerFactory emf;
Another value-added feature in WebLogic server 10.x is support for vendor-specific
subinterfaces of the EntityManager interface . For example, the BEA Kodo persistence
provider provides the KodoEntityManager subinterface , which may be injected with
the persistence context as follows:
private KodoEntityManager em;
Setting the environment
Before getting started, we need to install Oracle JDeveloper 11g, which may be
downloaded from http://www.oracle.com/technology/products/jdev/index.
html. Download the Studio Edition, which is the complete version of JDevloper
with all the features. Oracle JDeveloper 11g is distributed as a GUiself-extractor
application. Click on the jdevstudio11110install application. The Oracle Installer
gets started. Click on Next in the Oracle Installer. Choose a middleware home
directory and click on Next.
Choose the Install Type as Complete, which includes the integrated WebLogic
Server, and click on Next.
Confirm the default Product Installation directories and click on Next.
The WebLogic Server installation directory is the wlserver_10.3 folder within
the middleware home directory. Choose a shortcut location and click on Next.
The Installation Summary lists the products that are installed, which include the
WebLogic Server and the WebLogic JDBC drivers. Click on Next to install Oracle
JDeveloper 11g and the integrated WebLogic Server 10.3.
We also need to install the Oracle database 10g/11g or the lightweight Oracle XE ,
which may be downloaded from http://www.oracle.com/technology/software/
products/database/index.html. When installing Oracle database, also install the
Creating a datasource in JDeveloper
Next, we create a JDBC datasource in JDeveloper. We shall use the datasource in the
EJB 3.0 entity bean for database persistence. First, we need to create a database table
in some sample schema, OE for example. Run the following SQL script in SQL *Plus:
CREATE TABLE Catalog (id INTEGER PRIMARY KEY NOT NULL, journal
VARCHAR(100), publisher VARCHAR(100), edition VARCHAR(100), title
VARCHAR(100), author VARCHAR(100));
A database table gets created in the OE sample schema.
Next, we need to create a JDBC connection in JDeveloper with Oracle database. Open
the Database Navigator or select the Database Navigator tab if already open. Rightclick
on the IDE Connections node and select New Connection.
In the Create Database Connection window, specify a Connection Name, select
Connection Type as Oracle (JDBC), specify Username as OE, which is the schema
in which the Catalog table is created, and specify the password for the OE schema.
Select Driver as thin, Host Name as localhost, SID as ORCL, and JDBC Port as
1521. Click on the Test Connection button to test the connection. If the connection
gets established, click on OK.
The OracleDBConnection gets added to the Database Navigator view. The
CATALOG table that we created is listed in the Tables.