Java Reference
In-Depth Information
Creating entity beans from tables
In this section, we create EJB 3.0 entity beans from database tables. Right-click on
the
Model
project node in the
Application
navigator and select
New
. In the
New
Gallery
window, select
Business Tier|EJB
in
Categories
and
Entities
from
Tables
in
Items
. Click on
OK
. Next, we define the
Persistence
Unit
for the entity beans. A
Persistence
Unit
defines a data source, and other database persistence properties
for creating and persisting entity beans. A persistence unit is defined in the
META-
INF/persistence.xml
configuration file. Click on
New
. In the
New
Persistence
Unit
window, specify a persistence unit
Name
(
em
for example). Specify a
JTA
Datasource
Name
. Earlier we created a connection
OracleDBConnection
. A data
source with JNDI name
jdbc/OracleDBConnectionDS
gets created by default
when the connection is created. The data source name is of the format
jdbc/
ConnectionNameDS
, in which
ConnectionName
is the variable; the connection
name is what changes based on the database connection defined in JDeveloper.
Specify
jdbc/OracleDBConnectionDS
as the
JTA
Datasource
Name
. The
TopLink/
EclipseLink
is used as the JPA persistence provider. Select the
Default
Database
Platform
and the
Server
Platform
as
WebLogic
10
. Click on
OK
. A new
Persistence
Unit
(
em
) gets defined. Click on
Next
. In the
Type
of
Connection
window, a
developer may select from an
Online
Database
Connection
, an
Offline
Database
Connection
, or a
Application
Server
Database Connection
. Select
Online
Database
Connection
and click on
Next
.
Search WWH ::
Custom Search