Java Reference
In-Depth Information
The entity bean class
The entity bean class is just a POJO class annotated with the
@Entity
annotation.
A
@NamedQuery
specifies a
findAll
query, which selects all the entity instances.
An entity bean that has caching enabled is persisted to a database; the entity bean
is serialized by caches. Therefore, the entity bean class implements the
java.
io.Serializable
interface. Specify a
serialVersionUID
variable that is used by
serialization runtime to associate a version number with the serializable class:
private static final long serialVersionUID = 7422574264557894633L;
The database columns are mapped to entity bean properties, which are defined as
private variables. The getter setter methods for the properties are also defined. The
identifier property is specified with the
@Id
annotation. The
@Column
annotation
specifies that the
id
column is not nullable:
@Id
@Column(nullable = false)
private long id;
By default the
id
column of type
INTEGER
is mapped to a field of type
Long
. Modify
the
id
field to type
long,
as usually id values are of primitive type. The entity bean
class is listed next:
package model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
@Entity
@NamedQueries({
@NamedQuery(name = "Catalog.findAll", query = "select o from Catalog
o")
})
public class Catalog implements Serializable {
private String author;
private String edition;
private static final long serialVersionUID = 7422574264557894633L;
@Id
@Column(nullable = false)
private long id;
private String journal;
private String publisher;
Search WWH ::
Custom Search