Creating an Entity Class

See Also

In Java EE 5 applications, you use entity classes to create persistent entity objects ("entities"). Entity classes are "plain old Java objects" (POJOs). Entity classes import the Java persistence library javax.persistence.Entity and are marked with the @Entity annotation in your source code.

To create an entity class:

  1. Right-click the module project node in the Projects window and choose New > Other.
  2. In the New File wizard, select Entity Class from the Persistence category.
  3. Enter the name of the class.
  4. Select the location where you want to save the entity class.
  5. Select an existing package from the Package drop-down list or type the name of a new package.
  6. Set the type of the variable you want to use as the primary key. The default type for the primary key is Long.
  7. Click Finish.

When you click Finish, the IDE generates the entity class and opens the class in the Source Editor. Annotations in the entity class define the primary key and the primary key generation strategy for the entity.

About Entity Classes

Entities have the following characteristics:

In Java EE 5 applications, entities created using entity classes share many of the characteristics of entity beans in J2EE applications. Unlike entity beans, entity classes are not restricted to EJB modules in enterprise applications. Entity classes can be located in an EJB module or a web module. Entity classes can also be used in Java SE applications.

When coding entity classes, you use annotations to map entities and entity relationships to a database. You do not need to use external XML descriptor files to map persistent objects to a database. The information about the data source is contained in a persistence unit.

See Also
Working with Enterprise Applications
Creating a Persistence Unit
Generating Persistent Entity Classes from a Database
Mapping Entity Classes

Legal Notices