Show TOC

Procedure documentationCreating Data Models with the JPA Diagram Editor Locate this document in the navigation structure

 

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.

Using the JPA diagram editor is possible if you are developing your application components in Development Component (DC) projects. You can use only one JPA diagram per DC project, and you cannot visualize entities from different DC projects in one JPA diagram.

Example 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:

This graphic is explained in the accompanying text.

End of the example.
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 vice versa.

  • 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 DC project

    More information: Creating Development Components

    Note Note

    If you have an existing data model stored in a local project, you can convert the local project to a DC project.

    More information: Migrating Standard Projects into Development Components

    End of the note.
  2. Enabled the Java Persistence facet on that DC project

    More information: Creating JPA Projects in the Developer Studio

  3. (Optional) Created your JPA entities in that DC project

  4. Opened the Java EE perspective in the SAP NetWeaver Developer Studio

Procedure

Task

Steps

Configuring the JPA diagram editor

  1. Choose   Window   Preferences   in the main menu.

  2. Select   JPA   Diagram Editor   in the properties tree.

  3. Specify the JPA diagram editor settings.

  4. Choose Apply, then choose OK.

Opening the JPA diagram

  1. In the Project Explorer, expand the node of the DC used to store your entities.

  2. In the context menu of the JPA Content node, choose Open Diagram.

Creating new entities

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

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

Importing existing entities (if any) within a DC project to the diagram

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

  • To import all entities, click the JPA diagram with the secondary mouse button and choose Show All Entities, or copy the JPA Content node from the DC 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 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.

    End of the note.

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 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.

    End of the note.
  • 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.

    This graphic is explained in the accompanying text.

  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.

    This graphic is explained in the accompanying text.

Refactoring entities and attribute types

Caution 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.

End of the caution.

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   Refactor Entity Class   Rename  , then complete the wizard.

  • Move the entity to another source package — in the context menu of the entity name, choose   Refactor Entity Class   Move  , 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.

More information about templates: 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 Note

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

End of the note.
  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   Remove All Entities from Diagram   ...and Save Changes  

  3. To remove all entities from the diagram without saving any unsaved changes to the data model, choose   Remove All Entities from Diagram   ...and Discard Changes  .