Persistence Documents

Contents

Step 1:

Prerequisites to install the jsr220-orm plugin
Step 2:

Opening the Persistence Views

Step 3: How to enable Persistence for your Project
     A.) Using the Project Properties      
     B.) Using the 'Add Persistence' Wizard
     C.) Using the Mapping View
Step 4: Making Java Classes Persistent
     A.) Using the Package Explorer
     B.) Using the Mapping View
Step 5: Using the Mapping View
Step 6: Using the Live ER View

Getting Started

Step 1: Prerequisites to install the jsr220-orm plugin 


You need to be running Eclipse 3.1 with JDK 1.5
The following plugins must be downloaded and installed before the jsr220-orm plugin can be installed:

* EMF: emf-sdo-xsd-SDK-2.1.0.zip
* GEF: GEF-SDK-3.1.zip
* JEM: JEM-SDK-1.1.zip
* WST: wtp-wst-sdk-0.7.zip

Back
Step 2: Opening the Persistence Views

• Go to window, open perspective

• Click on Other

• Click on Persistence

There are now 2 new views: Mapping View and Live ER View.
• The Mapping view is where you set the options for classes and attributes using the class modifier.

• The Live ER view is where you set the database specifics, like table and column names, etc.

Back

Step 3: How to enable persistence for your project

A.) Using Project Properties

• Go to your project properties

• Click on Persistence

There are 5 properties which can be set: Persistence Product, Database, Version, Connection and Schema.


• Persistence Product – Select Generic EJB Persistence from the Persistence Product drop down list

• Database - Select the type of database you will be using

• Version – Select the appropriate version number of your database type.

• Connection – Select an existing database connection

Clicking on the Connection Hyperlink will display a popup enabling you to make a RDB Connection.

• Schema - Select the default schema to work with for the database connection

Back

B.) Using the 'Add Persistence' Wizard

• Go To File, click on New

• Click on Other

• The ‘Select a Wizard’ popup is displayed.

• Select persistence

• Click on Add Persistence

• Then Click on ‘Next’

• This will take you to the Persistence popup which is described in 'Using the Project Properties'’ section.

Back

C) Using the Mapping View
• Go to Window, click on ‘Open Perspective’

• Click on ‘Other’

• Click on Persistence

Back

Step 4: Making Java Classes Persistent

A.) Using the Package Explorer

• Go to the package Explorer View


• Navigate to the Java class you wish to make persistent.
• Right click the class.

• Click Persistence, Make Persistent

• Click on the link to the Java class to make it persistent.
The mapping view will only show this when a non-persistent class is open in the java editor.

Back

B.) Using the Mapping View

• Open the class you wish to make persistent in the Java Editor.

• The Mapping view indicates whether a class is already persistent or not
• Click on the class hyperlink to make it persistent.

Back

Step 5: Using the Mapping View

• You are able to make a single class persistent using the Mapping view by clicking on the hyperlink indicated

• Mapping new changes to see all options:
o Schema Name
o Access Type
o ID Class
Clicking on the ID Class hyperlink displays a standard eclipse type selector popup.

o ID Generator Type
o ID Generator Name

• When clicking on a class attribute the Mapping view changes to show current mappings.

The mapping view indicates the relationship of the selected field in the source code with the class. For example – a Contact may have many addresses.

The fetch type indicates how the field values are returned from the database.


The Optional Checkbox indicates whether it is a required value or not – whether it allows nulls.

The class is now persistent (Changes in the java source reflect the persistence immediately by showing ‘@Entity’ over the class name).

Standard EJB3 annotations are used. Defaults aren’t shown in the source code, but if changed from default then displayed in source code. This is according to EJB specification.

As you make changes in the mapping view it immediately reflects in the source code editor and in the Live ER view.

Back

Step 6: Using the Live ER View

The Live ER View reflects the database table of the persistent class, seen in the Java editor.


All the values in the Live ER view are editable, and any changes made are immediately reflected in the java class, and viewed in the Java editor.

For Example: the city length was changed from 255 to 300.

The change is immediately reflected in the source code displayed in the java editor.

When clicking on an attribute in the Live ER view – the properties are displayed on the right of the screen.

When clicking on a field in the source code of a persistent class, the Mapping view changes and the Live ER view changes to show columns relevant to the field.

For example: Click on contactNumbers in the Java class displayed in the Java editor.

Mapping View changes to show:

Live ER View changes to show:

The ellipse symbol is used in the Live ER View to show additional columns.

If you click on the ellipse, the table will expand to show the other columns belonging to the table. This is a very useful feature when there are many columns in the table.

The primary key on the table is displayed with a key to the left of the field name - and relationships to other tables are also indicated along with the relational column, as shown in below.

 

When you have a database connection, the Live ER View is colour coded according to a comparison between the class and the relative database table.

If all column names and data types are black – then the table and class are perfectly matched.

Blue columns are present in the database, but are not yet mapped to the class. Red columns are mapped columns that do not exist in the database.

Most likely the default column names will not be correct for a legacy database, in this case there will be a blue and red column on the Live ER. To change the column mappings, drag a blue column onto the corresponding red column. This will change the name and data type of the column and it will reflect in the source code and will appear as a single column.