Show TOC

Creating Data Models with the JPA Diagram EditorLocate this document in the navigation structure

Use

The SAP NetWeaver Developer Studio provides a JPA diagram editor tool that allows you to create, edit, and display the application data model (entities and their relationships) in a graphical environment.

You can use only one JPA diagram per project, and you cannot visualize entities from different projects in one JPA diagram.

Example

The following JPA diagram represents the data model of employees participating in various projects, that is, two entities with a bidirectional many-to-many relationship:

Features

The JPA diagram editor comprises the following general features:

  • Ability to create entities and define relationships between them.

  • Ability to import existing entities together with their relationships.

  • Full synchronization with the underlying application code, that is, whenever you apply a change to any of the objects on the diagram, the corresponding application code updates automatically, and the opposite.

  • Error and warning markers with informative quick info text. You can view details on the marked errors and warnings in the Problems view.

  • Integration with the JPA Details view and the Miniature View .

Prerequisites

You have:

  1. Created a project to store your entities

  2. Enabled the Java Persistence facet on that project

    For more information, see Creating JPA Projects in the Developer Studio .

  3. (Optional) Created your JPA entities

  4. Opened the Java EE perspective in the Developer Studio

Procedure

Task

Steps

Configuring the JPA diagram editor

  • Configure the global default settings of the JPA diagram editor

    1. Choose Start of the navigation path Window Next navigation step Preferences End of the navigation path in the main menu.

    2. Select Start of the navigation path General Next navigation step Editors Next navigation step JPA Diagram Editor End of the navigation path in the properties tree.

    3. Specify the JPA diagram editor settings. To restore the settings to the AS Java predefined values, choose Restore Defaults .

    4. Choose Apply , then choose OK .

  • Configure the JPA diagram editor per project

    1. In the context menu of the project in the Project Explorer , choose Properties .

    2. Select Start of the navigation path Java Persistence Next navigation step JPA Diagram Editor End of the navigation path.

    3. Specify the JPA diagram editor settings. To restore the global default settings, choose Restore Defaults .

    4. Choose Apply , then choose OK .

Opening the JPA diagram

  1. In the Project Explorer , select the project that you are using or want to use for your entities.

  2. In the context menu, choose Start of the navigation path JPA Tools Next navigation step Open Diagram End of the navigation path.

Creating new entities

In the Entities list of the Palette , choose Entity, then click the diagram area.

The Developer Studio creates the new entity with a predefined name and a primary key.

Displaying existing entities (if any) within a project on the diagram

  • To display a single entity, copy the entity using drag and drop from the Project Explorer to the JPA diagram.

  • To display all entities, click the JPA diagram with the secondary mouse button and choose Show All Entities , or copy the JPA Content node from the project in the Project Explorer to the JPA diagram, using drag and drop.

Defining and removing relationships between entities

  1. In the Relations list of the Palette , choose a relationship type.

  2. Click the source entity of the relationship with the primary mouse button or choose ESCAPE to cancel.

  3. Click the target entity of the relationship with the primary mouse button or choose ESCAPE to cancel.

    The Developer Studio creates and visualizes the relationship, as well as the relevant relationship attributes of the entities, depending on the type of relation.

  4. To remove a particular relationship, select the relation on the JPA diagram and choose DELETE , or choose Delete in the context menu.

    Note

    Removing a relationship via the JPA diagram also removes it from the application data model and deletes the relationship attributes of the two related entities.

Managing entities

You can perform the following operations on a particular entity graphical model:

  • Rename entities

    In terms of source code, this operation changes the name attribute of the @Entity annotation only.

  • Add, rename, or remove attributes

    Note

    The Developer Studio automatically generates getter and setter methods for new attributes. The default data type for new attributes is java.lang.String .

    In terms of source code, renaming attributes changes the field names of entities, together with the fields' getter and setter methods.

    Removing attributes removes them from the data model also.

  • Collapse or expand entities or attribute groups

  • Save or discard your changes

  • Save or discard your changes and remove the entity from the diagram without removing it from the application data model

  • Remove the entity from the diagram and delete it from the application data model

To perform the actions described above, follow the steps:

  1. Position the mouse cursor over the entity you want to manage.

    A button bar appears by the entity.

  2. Choose the relevant pushbutton. Each button has an informative tooltip that describes the relevant operation.

  3. To rename an entity or an attribute, double-click the title of an entity or the attribute, change the name, and choose ENTER .

  4. To remove an attribute, click the attribute and choose DELETE or choose Delete in the context menu.

    You can also remove an attribute by positioning the mouse cursor over the attribute and choosing the Delete Attribute pushbutton.

Refactoring entities and attribute types

Caution
  • If you rename or move an entity using a different approach (for example, via the Project Explorer ), the entity disappears from the JPA diagram.

  • When you refactor an attribute type, any existing business logic within the attribute's access methods is deleted.

Using the JPA diagram editor, you can perform the following refactoring operations:

  • Rename the entity class - in the context menu of the entity name, choose Start of the navigation path Refactor Entity Class Next navigation step Rename End of the navigation path, then complete the wizard.

  • Move the entity to another source package - in the context menu of the entity name, choose Start of the navigation path Refactor Entity Class Next navigation step Move End of the navigation path, then complete the wizard.

  • Refactor an attribute type - in the context menu of an attribute, choose Refactor Attribute Type , change the type, and choose OK .

Viewing and editing entities' source code

To view and edit the source code of a particular entity, double-click the title of the corresponding entity block on the diagram.

The Developer Studio opens the entity class in the standard source code editor.

When you apply changes to the source code, they are automatically synchronized with the diagram.

Applying templates to entities

The Developer Studio allows you to apply a predefined “template” (for example, a session bean CRUD facade) on entities within the diagram.

  1. Click the name of the entity with the secondary mouse button.

  2. In the context menu, choose Apply Template .

    The Apply Template wizard opens.

  3. Follow the steps and complete the wizard.

For more information about templates, see Generating Applications Based On Predefined Templates .

Opening the Miniature view or the JPA Details view

  1. Click the JPA diagram with the secondary mouse button.

  2. Choose Open Miniature View or Open JPA Details View , respectively.

  3. To save the diagram as an image, choose Save as Image .

Removing all entities from the diagram

Note

This operation removes the entities from the JPA diagram only, that is, they are not removed from the underlying application data model.

  1. Click the JPA diagram with the secondary mouse button.

  2. To save any unsaved changes to the application data model, and remove all entities from the diagram, choose Start of the navigation path Remove All Entities from Diagram Next navigation step ...and Save Changes End of the navigation path

  3. To remove all entities from the diagram without saving any unsaved changes to the data model, choose Start of the navigation path Remove All Entities from Diagram Next navigation step ...and Discard Changes End of the navigation path.