Create a simple JPA Domain Model using Enterprise Architect

This is a small tutorial on how to model a very simple Domain Model, as a UML Class model.
This model can be used for code generation using TRIMM (e.g. such as TRIMM JPA – see the TRIMM JPA Tutorial)

Model your domain model in UML using Enterprise Architect (EA)

You can also use MagicDraw to UML model your domain model – this will be covered in a later tutorial

1 Start Enterprise Architect

Start Enterprise Architect

Start Enterprise Architect

2 Create a EA Project file name and location

From the Open Enterprise Architect Project dialog press the New Project button

New EA project

New EA project

3 Select New EA Project location

Select the model folder within the folder where the Maven project was created in Step 1 (e.g. C:TRIMM-examples\firstjpaproject\model) and give the project a name, e.g. FirstJPAModel.eap

Select EA project file name and location

Select EA project file name and location

4 Select Domain Model from Model Wizard

From Basic UML 2 Technology select Domain model

Select Domain Model from Model Wizard

Select Domain Model from Model Wizard

5 Delete example classes and diagram

The wizard creates an example model which we don’t want to use, so you have to manually delete those until the contents look like the image below

Empty EA Domain Model project

Empty EA Domain Model project

6 Add new Diagram

Right click the Model element and select Add > Add Diagram…

Add Diagram

Add Diagram

7 Select Class diagram type

From UML Structural select Class diagram type and give it a name (e.g. model)

Select Class diagram type

Select Class diagram type

Which gives this result

Class diagram added

Class diagram added

8 Select Class from the toolbox and click the diagram canvas to add it

Add a Class called Member

Add a Class called Member

9 Add Attributes to the Class called Member

Right click the class called Member and select Attributes…

Add Attributes to Class

Add Attributes to Class


Add New Attribute

Add New Attribute

In Name enter email
In Type enter String
Click Save

Press New to add a new Attribute

To complete the Class Member add all following attributes:

Name Type
email String
firstName String
lastName String
numberOfActiveMembers int

Read Only attributes

numberOfActiveMembers should have been ReadOnly but EA version 9.x have removed that option, so we will handle it differently in our code – See Step 8 in the TRIMM JPA tutorial

All attributes added to Class Member

All attributes added to Class Member

10 Add two more classes

Add a class called Offer and a Class called OfferType

11 Add Attributes to class called Offer

To complete the Class Offer add all following attributes:

Name Type
dateExpiring LocalDate
value int

Unknown types

Enterprise Architect and TRIMM is a powerful combination, which allows you to reference Java types which are not defined in the UML model (because it would cumbersome to define all of the basic types). So here we define a type called LocalDate (which is unknown to UML) and which is unknown to Java. Later on in this tutorial we will show how to map LocalDate to a real Java type (from the JODA time library)

Add Attributes to class Offer

Add Attributes to class Offer

12 Create a composite association between Member and Offer

Select the Composite association icon in the Toolbox’s Class Relationships

Select Composite association icon

Select Composite association icon

Click on Class Offer and drag an association line between it and the class Member (release the mouse button when the line is within the Member class)

Drag association from Offer to Member

Drag association from Offer to Member

Composite Associations

A Composite Association between Member and Offer, where the composite (filled icon) is placed next to Member, means that there’s a Parent-Child relationship between Member and Offer in the sense that Member owns its Offers and if we deleted a Member we also want to delete its Offers.

Create composite association between Member and Offer

Create composite association between Member and Offer

13 Configure the Member – Offer association

Double click or Right click the association and select Properties
In the Aggregation Properties dialog select Direction value Bi-Directional, which means that a Member knows its Offers and an Offer known which Member it’s owned by.

Bidirectional association

Bidirectional association

Naming association Source Role and setting its Multiplicity

In the same Aggregation Properties dialog select the Source Role (which is Offer since we dragged the association from Offer to Member).
Give Offer Role the role name: assignedOffers a set its Multiplicity to 0..* (which means a Member can have many Offer’s)

Offer role configuration

Offer role configuration

Naming association Target Role and setting its Multiplicity

In the same Aggregation Properties dialog select the Target Role (which is Member since we dragged the association from Offer to Member).
Give Target Role the role name: memberAssigned a set its Multiplicity to 1 (which means the an Offer must be assigned to a Member to be valid)

Target role configuration

Target role configuration

14 Add Enumeration class called ExpirationType

Select the Enumeration icon in the Toolbox

Add Enumeration Class

Add Enumeration Class

Add the Enumeration to the diagram and name it ExpirationType

Add Attributes to Enumeration ExpirationType

Right click the ExpirationType enumeration and select Attributes… (just like when working with normal classes – in fact ExpirationType is a normal class which has had the <> stereotype applied to it by EA)
Add Attributes Assignment and Fixed (Notice Enumeration attributes doesn’t have a Type)

Add attributes to Enumeration

Add attributes to Enumeration

15 Create an Association between OfferType and ExpirationType

Select the Association type icon from the ToolBox’s Class Relationships section

Select Association icon

Select Association icon

Click the Association icon and click OfferType and drag the association on to ExpirationType

Drag association between OfferType and ExpirationType

Drag association between OfferType and ExpirationType

Configure the Association between OfferType and ExpirationType

Double click the association between OfferType and ExpirationType (or right click it and select Properties)
Change the Direction to be Source -> Destination (so our uni directional association points in the right direction)

Configure OfferType to ExpirationType association

Configure OfferType to ExpirationType association

16 Create Composite Association Between Offer and OfferType

Click the Composite Association icon (in the Tool Box’s Class Relationships section).
Click OfferType and drag the association onto Offer

Create Composite Association between Offer and OfferType

Create Composite Association between Offer and OfferType

Adjust the Association to be directed from Offer to OfferType

Double click the Association between Offer and OfferType or Right click it and select Properties.
In the Aggregation Properties dialog change the Direction to Destination -> Source (Destination is Offer since that where we dragged the association towards)

Adjust Source Role name and Multiplicity

Click on the Source Role (in the same Aggregation Properties dialog (Source is OfferType since that’s where we dragged the association from)
Set its Name to type and its Multiplicity to 1

Adjust Offer to OfferType association Source Role

Adjust Offer to OfferType association Source Role

17 Final model

After completing these steps your model should look like the model below:

Complete JPA model

Complete JPA model

< Back