Creating JPA entity beans

You can create JPA entity beans from existing database tables or you can create JPA entity beans then generate database tables from the JPA entity beans.

 

Creating JPA entity beans from existing database tables

Create a JPA enabled dynamic Web project.

To create a JPA entity bean from existing database tables:

  1. In Enterprise Explorer, right-click your JPA enabled Web project and select

    JPA Tools | Generate Entities. The Generate Entities wizard opens.

  2. On the Database Connection page of the wizard, specify the connection name and the connection schema. Click Next.

  3. On the Generate Entities from Tables page of the wizard, type a package name.

  4. Click

    Synchronize Classes in persistence.xml. This option enables automatic synchronization of the persistence.xml with any JPA resources in your workspace.

  5. In the Tables list, select the tables for which you want to generate entities. Click Finish.

The JPA entity beans are added to your Web project. You can view them in the JPA Content node.

 

Generating database tables from JPA entity beans

Create a JPA enabled dynamic Web project.

To generate database tables from entity beans:

  1. Create a JPA entity bean.

  2. Generate a data definition language (DDL) file.

  3. Create a database connection for the project:

    1. Right-click your Web project and select

      Properties.

    2. From the Properties list, click

      JDBC Connections.

    3. Click

      New. Follow the instructions in the wizard to create a connection to a database.

  4. Generate database tables from the DDL file.