Creating JPAs for Websphere in RAD

This is a distillation of a number of examples and technology quickstarts that explains how to create and use JPA objects in RAD 8.0.4. I’m creating this mostly for my own use, because it’s a long and involved process and it’s hard to fix missteps after they occur, but I thought others might find it helpful as well

  1. Create a new workspace
    1. You should have a Websphere 7 or later server in the workspace
  2. Create a JPA project
  3. Configure the JPA project
    1. set the target server
      1. right-click the project, select properties, select “Server”, select the target server you want
    2. select the targeted run time
      1. in the project properties dialog, select “targeted runtimes”; select your server’s runtime and click finish
    3. add JPA support
      1. in the project properties dialog, select “project facets”, select “JPA”, and click finish.
    4. create a database connection
      1. in the project properties dialog, select “java persistence”,
        1. under “platform,” select “RAD JPA 2.0 Platform”
        2. under “connection,” click “add connection”
          1. set up a connection to your target database
          2. click “test connection” to make sure it worked
          3. click “finish”
        3. check “override default schema from connection” and select the schema you want to use
    5. at this point you’ve got a configured project, and it’s time to add entities
  4. Generate JPA entity beans
    1. right-click the project and select JPA Tools > Generate Entities from Tables
    2. on the first dialog
      1. select the connection and schema you want to use
      2. select the tables you want to create
      3. make sure that “update classes in persistence.xml” is checked
      4. click next
    3. on “table associations”, click next
    4. on “customize default entity generation”
      1. enter a name in the “package” field for the package you want to put the entities in
      2. click “finish”
  5. Add primary keys and named queries
    1. right-click the project and select JPA Tools > Configure JPA Entities
    2. on the “configure JPA entities” dialog
      1. check any entities that you want to configure
      2. click “next”.
    3. on the “tasks” page
      1. one by one, select each object and do the following:
        1. select the “primary key” task and choose a primary key
        2. select the “named queries” task and click the “default” button to create a standard set
        3. select the “other” task and select “Add an equals and hashCode method if not present.”
    4. Click “finish”
  6. Configure the project for deployment
    1. right-click the project and click JPA Tools > Configure Project for JDBC deployment.
      1. select the connection you want from the “connection” dropdown
      2. ensure that your schema is selected
      3. accept the other defaults and click “OK”.
  7. Create entity managers
    1. right-click the project and click JPA Tools > Add JPA Manager Beans
    2. select all the beans for which you want to create entity managers
    3. click finish

At this point, your JPA project should be ready to use

Advertisements