The Dali JPA Tools project provides JPA support for Eclipse. This support is directed at minimizing the complexity of mapping by providing wizards for the creation and automated initial mapping. Programming assistance in the form of dynamic problem identification is also provided.
Since its inception as an Eclipse project, Dali has been used for developing JPA entities deployed to TopLink Essentials (JPA reference implementation).
This How-To document demonstrates the use of TopLink Essentials with Dali to compile and run JPA entities. Note that this document is not a Dali tutorial and assumes your familiarity with Dali. For more information, see the Dali Homepage at Eclipse.org.
Dali supports a number of different JPA development and deployment scenarios including EJB, Web, and plain old Java. The key difference between these scenarios is the configuration of the run-time classpath environment. When your application is running inside a Java EE or Servlet container, it inherits some JAR files from the container. When you are running a simple Java SE application, the classpath configuration is completely under your control. This How-To document focuses on the Java SE case making the use of the explicit classpath configuration.
You can start by performing the following steps:
Create a Java project in Eclipse;
Download TopLink Essentials by clicking Download located at the top of the sidebar on the right. Follow the download instructions to extract the TopLink Essentials JAR files into a temporary folder.
Add the JAR files to your Java project.
Begin. Your environment is ready, when it looks similar to the following illustration:
If you are using the Dali 0.5 release, enable the JPA tool support for your project by following this procedure:
Select Java Persistence > Add Java Persistence menu option.
In the Add Java Persistence dialog box, specify a database connection and configure the project build path, as the following illustration shows:
3. Click the Build Path hyperlink to open the Java Build Path section of the Project Properties dialog box.
4. Click Add JARs... to add the toplink-essentials.jar to your classpath:
5. On the JAR Selection dialog box, select the toplink-essentials.jar, and then click OK.
6. Close the Project Properties dialog box.
7. Click Finish on the Add Java Persistence dialog box.
Your project classpath now includes the toplink-essentials.jar file. Note that the toplink-essentials-agent.jar should not be on your classpath at this moment.
Compiling an Entity
With your classpath set, you can start creating an entity: define a new Address entity, as the following illustration shows. Note that, with the toplink-essentials.jar on your classpath, the imports of the javax.persistence package can be resolved.
For more information on using Dali for entity creation, editing, and validation see Dali User's Guide.
Running an Application With TopLink Essentials
To run an application that uses TopLink Essentials JPA, you also need the following:
The first two items in the preceding list are standard JPA features and are covered elsewhere.
You can create the run configuration for your Java application using the Run > Run... menu option: the Run dialog box opens, as the following illustration shows (for Eclipse 3.2). Select Java Application from the list on the left, and then click New to create a new run configuration:
The following illustration shows the newly created run configuration. The Main tab contains settings for the Project as JPA Demo project, and for the main class as model.Main.
Open the Arguments tab to specify the java agent:
In the VM arguments field of the Arguments tab, enter -javaagent:toplink-essentials-agent.jar and click Apply.
Now, to run the model.Main you can run the run configuration called main (specified in the Name field). Once you run it, it becomes the default run configuration: from now on, when you click Run (represented by the green icon on the Eclipse toolbar) it will run again without you selecting it from the Run menu.
Running TopLink Essentials applications in Eclipse is a matter of configuring the classpath and defining a run configuration. The combination of TopLink Essentials, Eclipse, and the Dali JPA Tools provides a completely open-source JPA development environment.