JPA Development in MyEclipse
JPA is a Hibernate-like persistence specification that became part of the Java EE 5 spec. JPA uses Java 5 annotations to control how plain Java classes (POJOs) get mapped to database tables.
You can create a JPA-enabled project by creating any of the supported types of base projects, like a Java or Web project, and then adding JPA facets to that project from the MyEclipse menu. To add JPA facets, right-click the project, and select MyEclipse>Project Facets>Install JPA Facet from the menu. You can also add multiple facets to a project simultaneously by opening the Project Facets propety of the project.
MyEclipse provides support for the OpenJPA, Hibernate, and EclipseLink JPA providers.
Associate your project with a database and schema for design-time tool support. The project in the image below is being associated with the database driver for the local MyEclipse Derby database.
Instead of relying only on libraries shipped with MyEclipse, you can download libraries to include in your project. Click the Download icon to add a user library.
You can change a JPA project's database driver association at any time using the Java Persistence properties page. To open this page, right-click the project, and select Properties from the menu. Expand MyEclipse>Project Facets, and select Java Persistence.
Right-click a JPA project, and select Generate Entities & DAOs from the menu. You are given an option to use either the MyEclipse reverse-engineering tools or the DALI entity generator. Making a select launches the respective JPA Reverse Engineering wizard.
You can also generate entities by right-clicking a table in the DB Browser view.
The reverse engineering process is fully customizable. Using the JPA Reverse Engineering wizard you can choose the artifacts to generate and the database tables from which the artifacts are based.
MyEclipse can also generate DAOs with result pagination support for findBy<property> queries. The generated result pagination API provides DAO clients fine-grained programmatic control to position to a specific row number of a result set and fetch n entities.
Following are several sample snippets of the code generated by the Reverse Engineering processor.
MyEclipse Java Persistence Perspective
The MyEclipse Java Persistence perspective provides an optimal editor and view layout for JPA-oriented tasks.
JPA Details View
The JPA Details view makes it easy to edit entity annotations.
JPA Diagram Editor
The JPA diagram editor allows you to easily create new entities or edit entities in your existing JPA projects.
JPA Annotation Table and Column Content Assist
JPA Entity Validation
Errors in your mapping are detected and displayed in the editor and Problems view.
The JPA Entity Validator can be enabled or disabled at the project level.
Spring 2 Support
When adding JPA facets to a project that already has Spring facets or vice versa, you can choose advanced Spring-JPA support. This level of support enables JPA tools to work with your project's Spring artifacts. The following image shows the Spring-JPA project configuration wizard.
Select Spring-JPA support, your primary bean configuration file, and customize bean Ids and transaction support.
Reverse Engineering Entities and Spring DAOs from Database
For projects that are configured to support advanced Spring-JPA capabilities, in addition to generating Entity classes from a database schema, Spring-compatible DAOs can be generated. During the reverse-engineering process, the Spring application context file is updated with generated bean entries for each DOA class.