Creating JPA manager beans

JPA Manager Beans are service beans that act as facades or controllers over a particular JPA entity. They encapsulate and abstract all of the data access code for creating, updating, deleting, and displaying information from your database using JPA entities.

  1. Create a JPA enabled dynamic Web project.

  2. Create a JPA entity bean.

JPA Manager Beans map one-to-one to a JPA entity. For example, if you have a Department entity, you can create a JPA Manager Bean named DepartmentManager, which contains all of the data access logic needed to work with the Department entity.

JPA Manager Beans are an ideal programming model for use in two-tier Web environments. They fill the role that would normally be filled by a session bean in an EJB environment. All of the business logic related to an entity is performed by the JPA Manager Bean.

The use of JPA Manager Beans is not limited to Web applications. They can be used anywhere that you want to take advantage of their data abstraction capabilities, such as an EJB project, a JPA Utility project, or even a plain Java™ project.

Note: If you want to use JPA inside of an EJB project, you may want to create an EJB Session Bean to contain all of your JPA logic.

JPA entities do not need to reside in the same project as the JPA Manager Beans. For example, your JPA entities can exist in a JPA Utility project or EJB project, and you can generate JPA Manager Beans for those entities inside of a Web project.

To Create a JPA manager bean:

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

    JPA Tools | Add JPA Manager Beans. The JPA Manager Bean wizard opens.

  2. In the Available JPA Entities list, select the entities for which you want to generate manager beans. Click Next.

  3. For each manager bean, you can configure:

    Primary Key

    For each manager bean, specify the primary key. The primary key uniquely identifies each record in a set of data.

    Query Methods

    Add new query methods, edit existing query methods, or delete query methods associated with a JPA Manager Bean. The query method is added to your JPA Manager Bean and determines which JPA data is displayed on the Web page.

    Relationships

    Add new relationships between JPA entities or delete relationships.

    Concurrency Control

    Specify the optimistic lock value for the entity. The optimistic lock value ensures that correct results for concurrent operations are generated.

    Advanced options

    Set advanced options.

  4. When you have completed configuring the entity bean, click Finish.

The JPA manager beans are added to the Java Resources/src/<package>.controller folder in your Web project, where <package> is the package you specified when you created your JPA entity beans.