Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.1.0) Part Number B28221-02 |
|
|
View PDF |
EJB 3.0 greatly simplifies the development of enterprise beans, removing many complex development tasks. For example:
The bean class can be a POJO; it does not need to implement javax.ejb.EntityBean
.
The business interface is optional. It can be a plain old Java interface (POJI).
Home (javax.ejb.EJBHome
and javax.ejb.EJBLocalHome
) and component (javax.ejb.EJBObject
and javax.ejb.EJBLocalObject
) business interfaces are not required.
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 a JPA Entity?".
Note:
You can download a JPA entity code example from:http://www.oracle.com/technology/tech/java/oc4j/10131/how_to/how-to-ejb30-entity-ejb/doc/how-to-ejb30-entity-ejb.html
.To implement a JPA entity, do the following:
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
.
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 a JPA Entity Primary Key".
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".
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".
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".
Complete the configuration of your entity bean (see "Using Java Persistence API").