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

  1. Create a JPA project or enable JPA support in an appropriate project. Ensure that an active database connection is defined for the project.
  2. Open the JPA perspective. (Click Window > Open Perspective > Other > JPA.)
  3. Create a Java class (File > New > Class).
  4. 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.
  5. 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:
  6. If you selected entity in the previous step, you can further configure the properties of the entity using the JPA details view.
  7. 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):
    Note: Entity (@Entity) persistent classes must have one attribute with an ID mapping.
Icon that indicates the type of topic Task topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: t_jpabean_create.html