Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-02 |
|
![]() Previous |
![]() Next |
This chapter explains how to implement an EJB 3.0 entity.
Note: In this release, OC4J supports a subset of the functionality specified in the EJB 3.0 public review draft. You may need to make code changes to your EJB 3.0 OC4J application after the EJB 3.0 specification is finalized and OC4J is updated to full EJB 3.0 compliance. For more information, see "Understanding EJB Support in OC4J".There are no OC4J-proprietary EJB 3.0 annotations. For all OC4J-specific configuration, you must still use the EJB 2.1 |
For more information, see:
EJB 3.0 greatly simplifies the development of EJBs, removing many complex development tasks. For example:
The bean class can be a plain old Java object (POJO); it does not need to implement javax.ejb.EntityBean
.
Home (javax.ejb.EJBHome
) and component (javax.ejb.EJBObject
) interfaces are not required.
If you choose to use a remote component interface, you can use a plain old Java interface (POJI); it does not need to extend javax.ejb.EJBObject
.
Annotations are used for many features, including container-managed relationships (object-relational mapping).
An EntityContext
is not required: you can simply use this
to resolve an entity to itself.
For more information, see "What is an EJB 3.0 Entity?".
Note: You can download an EJB 3.0 CMP entity code example from:http://www.oracle.com/technology/tech/java/oc4j/ejb3/howtos-ejb3/howtoejb30entity/doc/how-to-ejb30-entity-ejb.html . |
To implement an EJB 3.0 entity:
Create the entity bean class.
You can create a plain old Java object (POJO) and define it as a CMP entity bean with the @Entity
annotation.
All data members are by default considered container-managed persistence fields unless annotated with @Transient
.
Define how OC4J persists your entity bean class to a database using the @Table
and @Column
annotations.
If you do not have an existing database schema, you can delegate table and column definition to OC4J by omitting these annotations: at deployment time, OC4J will create default table and column names based on class and data member names.
For more information, see "Configuring Table and Column Information".
Define one data member as the primary key field with the @Id
annotation.
You can annotate the data member itself or its getter method. For more information, see "Configuring an EJB 3.0 Entity Primary Key".
Define container-managed relationships using the appropriate object-relational mapping annotations, such as @OneToOne
.
For more information, see "Configuring an EJB 3.0 Entity Container-Managed Relationship Field".
Optionally, define finders and queries using the @NamedQuery
annotation.
At runtime, you can use the predefined finders (see "Predefined TopLink Finders") and default finders (see "Default TopLink Finders") that the TopLink persistence manager provides.
For more information, see "Using EJB 3.0 Query API".
Optionally, define lifecycle callback methods using the appropriate annotations.
You do not need to define lifecycle methods: OC4J provides an implementation for all such methods. Define a method of your entity bean class as a lifecycle callback method only if you want to take some action of your own at a particular point in the entity bean's lifecycle.
For more information, see "Configuring a Lifecycle Callback Method for an EJB 3.0 Entity".
Complete the configuration of your entity bean (see "Using EJB 3.0 Persistence API").