Creating a JPA entity bean by adding persistence to a POJO
With the JPA Tools, you can create a JPA entity bean and add persistence to plain old Java™ objects (POJOs).
Procedure
- Create a JPA project or enable JPA support in an appropriate project. Ensure that an active database connection is defined for the project.
- Open the JPA perspective. (Click Window > Open Perspective > Other > JPA.)
- Create a Java class (File > New > Class).
- In the Package Explorer view, right-click on the new class and select JPA Tools > Make Persistence. You can select Annotate in Java and List in persistence.xml. Click Next. Specify the database table to map and click Next to specify the mapping of the bean attributes to database columns. Click Finish.
- The new class now appears in the JPA structure view. Click it to go to the JPA Details view. To change the mapping type, click the type that the class is mapped to. You can add the following types of persistence to the class:
- If you selected entity in the previous step, you can further configure the properties of the entity using the JPA details view.
- For each attribute in your persistent class, you can specify
the mapping of the attribute. In this step, you define how each class
attribute maps to the database. In the JPA Structure view, click the
attribute that you want to map, and then in the JPA Details view,
click the Map As drop-down list. You can choose
the following types of mappings (see the Java Persistence Tools
User Guide for details on completing the fields):
- Basic mapping
- Embedded mapping
- Embedded ID mapping
- ID mapping
- Many-to-many mapping
- Many-to-one mapping
- One-to-many mapping
- One-to-one mapping
- Transient mapping
- Version mapping
Note: Entity (@Entity) persistent classes must have one attribute with an ID mapping.
Parent topic: Creating JPA entity beans

