@Deprecated

Example

Here's a simple example of how to use EclipseLink JPA in an Eclipse Rich Client Platform (RCP) application. For simplicity the application will be headless--which really makes you wonder how "rich" this client is. ;-) But for those of you building RCP applications who need JPA Persistence I think this will provide the minimum of what you need to get going. I'll keep it pretty high level on the assumption that the reader is familiar with RCP and PDE and just wants to add in some EclipseLink JPA. We'll use Derby for our database.

Setup

Using the New Wizard create a Plugin Project targeted at Eclipse 3.3 or 3.4

Do not generate an Activator, do not contribute to the UI, but say yes to "Would you like to create a rich client application?"

Select the "Headless Hello RCP" template.

Drag and drop the following jars into your project:

eclipselink.jar

persistence.jar

derbyclient.jar (or jdbc driver of your choice)

Add these jars to your runtime classpath in your manifest.mf

An Entity

Add a class to your project you want to persist. I'll add "Publisher" and add the necessary JPA annotations for persistence (all two of them).

The Application

And finally the Application. It implements IApplication and I put the code I want to run into the start(..) method. It looks like most Java SE JPA code it: creates an EntityManagerFactory, obtains an EntityManager, performs a query, closes the EntityManager, and in the stop() method it closes the EntityManagerFactory. In a non-headless (it's a double negative but what else can you call it?) application you'd probably move the management of EntityManagerFactory and Entities somewhere else so as to be able to access them from various views.