Java Reference
In-Depth Information
The entity bean class
An entity bean in EJB 3.0 is just a POJO (Plain Old Java Object) annotated with the
@Entity annotation. Entity bean mappings to a relational database are defined using
metadata annotations. Simply annotating a POJO class with the @Entity annotation
makes it an entity bean. The @Table annotation is used to specify the database
schema and table name to which the entity bean is mapped. If the @Table annotation
is not specified, the entity bean class name is used for the default table name. The
class declaration of the Catalog class consists of an @Entity annotation and an
@Table annotation.
public class Catalog implements Serializable {
If a cache-enabled entity bean is persisted to a database via an EntityManager , the
entity bean is added to the cache. Similarly, if you update/remove a cache-enabled
entity bean to a database via an entity manager, the entity bean is updated/removed
from the cache. Therefore, an entity bean is recommended to implement the java.
io.Serializable interface. We also need to specify the serialVersionUID ,
which is used by the serialization runtime to associate a version number with the
serializable class. In the entity bean class, specify the POJO properties catalogId ,
journal , publisher , edition , title , and author . Add the getter and setter
methods for the entity bean properties. Specify the identifier property, which is
mapped to the primary key of a database table, with the @Id annotation. The
Catalog class includes a constructor that creates a Catalog entity instance from the
entity bean properties. The entity bean class Catalog is listed below.
package model;
import javax.persistence.*;
@Table(name = "Catalog")
public class Catalog implements Serializable {
private static final long serialVersionUID = 7422574264557894633L;
private String catalogId;
private String journal;
private String publisher;
private String edition;
private String title;
private String author;
Search WWH ::

Custom Search