Java Reference
In-Depth Information
public void setPublisher(String publisher){
this.publisher=publisher;}
}
The XSL transformation generated entity class may require some reformatting or/
and debugging depending on the complexity of the initial EJB 2.0 entity. The EJB 3.0
entity generated in this chapter requires only slight reformatting. The EJB 3.0 entity
class has the import statements for the
javax.persistence
package classes. The
@Entity
annotation specifies the class as an entity EJB class. The
@Table
annotation
specifies the database table name for the entity EJB, the
@NamedQueries
annotation
specifies the named queries, the
@Id
annotation specifies the identifier property/
primary key field, and the
@Column
annotation specifies the database column
corresponding to the identifier property. The EJB 2.0-to-EJB 3.0 conversion XSLT also
includes the conversion of entity bean CMR relationships.
Developing a session façade for an entity
In EJB 2.0, an entity bean is created with the
create
method in the
home/local
home
interface and the entity bean fields are modified with the getter/setter methods in
the
local/remote
interface. In EJB 3.0, an entity bean is created and modified with
the
EntityManager
API. The
EntityManager
class provides methods for finding,
persisting, and removing an entity bean instance. This section covers generation of a
session bean that implements the
EntityManager
API.
In the session bean class, the
EntityManager
is obtained with the
@Resource
annotation:
@Resource private EntityManager em;
Some of the commonly used methods of the
EntityManager
class are listed in the
following table:
EntityManager Method
Description
persist(Object entity)
Saves an entity bean instance in the
database. The persist method returns
the entity bean that is persisted in the
database.
find(String entityName, Object
primaryKey)
Finds an entity bean instance with a
primary key.
remove(Object entityBean)
Removes an entity bean from the
database.
createQuery(String ejbQlString)
Creates an EJB QL query.
createNamedQuery(String queryName)
Creates a @NamedQuery query.
Search WWH ::
Custom Search