Creating an entity

The creation of a simple entity is not difficult and is accomplished using the @Entity annotation. The essence of the process is demonstrated here and elaborated upon in subsequent recipes.

Getting ready

The creation of an entity involves two steps:

  1. Annotating a class with the @Entity annotation
  2. Adding methods to provide access to the fields of the entity

    An entity is frequently added using a wizard provided by an IDE. This frequently involves specifying a primary key and the creation of a persistence unit. The primary key is used to optimize access to the underlying database table and the persistence unit provides mapping from the entity to the underlying data store.

How to do it...

Create a Java EE application called EntityBeanApplication ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.