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

Implementing a JPA Entity

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

For more information, see "What is a JPA Entity?".

To implement a JPA entity, do the following:

  1. Create the entity bean class.

    You can create a POJO and define it as an entity bean with container-managed persistence using the @Entity annotation.

    All data members are by default considered container-managed persistent 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 a JPA Entity Primary Key".

  4. Define container-managed relationships using the appropriate object-relational mapping annotations, such as @OneToOne.

    For more information, see "Configuring a Container-Managed Relationship Field for a JPA Entity".

  5. Optionally, define finders and queries using the @NamedQuery annotation.

    At run time, 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 "Implementing JPA Queries".

  6. Optionally, define life cycle callback methods using the appropriate annotations.

    You do not need to define life cycle methods: OC4J provides an implementation for all such methods. Define a method of your entity bean class as a life cycle callback method only if you want to take some action of your own at a particular point in the entity bean's life cycle.

    For more information, see "Configuring a Life Cycle Callback Method on a JPA Entity".

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