Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3)
B14428-02
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

6 Implementing an EJB 3.0 Entity

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 orion-ejb-jar.xml file.


For more information, see:

Implementing an EJB 3.0 Entity

EJB 3.0 greatly simplifies the development of EJBs, removing many complex development tasks. For example:

For more information, see "What is an EJB 3.0 Entity?".

To implement an EJB 3.0 entity:

  1. 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.

  2. 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".

  3. 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".

  4. 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".

  5. 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".

  6. 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".

  7. Complete the configuration of your entity bean (see "Using EJB 3.0 Persistence API").