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.
The creation of an entity involves two steps:
- Annotating a class with the @Entity annotation
- 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