0% found this document useful (0 votes)
18 views78 pages

Dali User Guide

The Dali Object-Relational Mapping Tool User Guide provides comprehensive instructions on installing and using the Dali tool within Eclipse for Java persistence. It covers creating projects, defining Java persistent entities, and mapping these entities to database tables, along with tutorials and reference materials. The document is intended for developers looking to implement object-relational mapping in their Java applications using Dali.

Uploaded by

sisazara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views78 pages

Dali User Guide

The Dali Object-Relational Mapping Tool User Guide provides comprehensive instructions on installing and using the Dali tool within Eclipse for Java persistence. It covers creating projects, defining Java persistent entities, and mapping these entities to database tables, along with tutorials and reference materials. The document is intended for developers looking to implement object-relational mapping in their Java applications using Dali.

Uploaded by

sisazara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

Dali Object-Relational Mapping Tool

User Guide
Release 0.5.0 for Eclipse

June 2006
Dali Object-Relational Mapping Tool User Guide

Copyright © 2006, Oracle. All rights reserved.

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated
below, the Content is provided to you under the terms and conditions of the Eclipse Public License Version
1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. For purposes of
the EPL, "Program" will mean the Content.

If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed
by another party ("Redistributor") and different terms and conditions may apply to your use of any object
code in the Content. Check the Redistributor's license that was provided with the Content. If no such license
exists, contact the Redistributor. Unless otherwise indicated below, the terms and conditions of the EPL still
apply to any source code in the Content.
Contents

1 Getting started
1.1 Requirements and installation .................................................................................................. 1-1
1.2 Dali quick start ............................................................................................................................ 1-1
1.2.1 Creating a new project ........................................................................................................ 1-2
1.2.2 Creating a Java persistent entity........................................................................................ 1-4
1.2.3 Mapping an entity ............................................................................................................... 1-6
1.3 Dali basic tutorial ........................................................................................................................ 1-8
1.3.1 Generate the tutorial database schema............................................................................. 1-8
1.3.1.1 Create a database connection...................................................................................... 1-9
1.3.2 Create a Java project ............................................................................................................ 1-9
1.3.2.1 Add persistence to the project ................................................................................. 1-10
1.3.3 Create persistent Java entities ......................................................................................... 1-11
1.3.3.1 Add fields to the entities........................................................................................... 1-12
1.3.3.2 Associate the entity with a database table ............................................................. 1-12
1.3.4 Create OR mappings ........................................................................................................ 1-13
1.3.4.1 Create ID mappings .................................................................................................. 1-13
1.3.4.2 Create basic mappings .............................................................................................. 1-15
1.3.4.3 Create one-to-one mappings.................................................................................... 1-16
1.3.4.4 Create one-to-many mappings ................................................................................ 1-18
1.3.4.5 Create many-to-one mappings ................................................................................ 1-18
1.3.4.6 Create version mappings.......................................................................................... 1-19

2 Concepts
2.1 Understanding Java persistence .............................................................................................. 2-1
2.2 Understanding OR mappings ................................................................................................... 2-1
2.3 Understanding JSR220: EJB 3.0 ................................................................................................. 2-2
2.3.1 The persistence.xml file....................................................................................................... 2-2

3 Tasks
3.1 Adding persistence to a Java project ....................................................................................... 3-1
3.2 Managing the persistence.xml file............................................................................................ 3-2
3.2.1 Working with persistence.xml file .................................................................................... 3-4
3.2.2 Synchronizing classes.......................................................................................................... 3-5
3.3 Adding persistence to a class ................................................................................................... 3-5
3.3.1 Persistent entity.................................................................................................................... 3-5

iii
3.3.2 Embeddable .......................................................................................................................... 3-6
3.3.3 Mapped superclass .............................................................................................................. 3-7
3.4 Creating a new Java persistent entity ...................................................................................... 3-8
3.5 Specifying entity inheritance..................................................................................................... 3-9
3.6 Mapping an entity ................................................................................................................... 3-10
3.6.1 Basic mapping ................................................................................................................... 3-11
3.6.2 Embedded mapping......................................................................................................... 3-12
3.6.3 Embedded ID mapping ................................................................................................... 3-13
3.6.4 ID mapping........................................................................................................................ 3-13
3.6.5 Many-to-many mapping.................................................................................................. 3-15
3.6.6 Many-to-one mapping ..................................................................................................... 3-16
3.6.7 One-to-many mapping..................................................................................................... 3-17
3.6.8 One-to-one mapping ........................................................................................................ 3-18
3.6.9 Transient mapping ........................................................................................................... 3-19
3.6.10 Version mapping .............................................................................................................. 3-20
3.7 Generating entities from tables ............................................................................................. 3-20
3.8 Generating tables (DDL scripts) from entities .................................................................... 3-21
3.9 Validating mappings and reporting problems .................................................................... 3-22
3.9.1 Error messages .................................................................................................................. 3-22
3.10 Modifying persistent project properties ............................................................................... 3-24

4 Reference
4.1 Wizards......................................................................................................................................... 4-1
4.1.1 Generate Database DDL from Entities wizard ................................................................ 4-1
4.2 Property pages............................................................................................................................. 4-1
4.2.1 Persistence Properties view (for entities) ......................................................................... 4-2
4.2.1.1 General tab..................................................................................................................... 4-2
4.2.1.2 Inheritance tab............................................................................................................... 4-2
4.2.2 Persistence Properties view (for attributes) ..................................................................... 4-3
4.2.2.1 General tab..................................................................................................................... 4-3
4.2.2.2 Join Table tab................................................................................................................. 4-5
4.2.2.3 Join Columns tab .......................................................................................................... 4-5
4.2.2.4 PK Generation tab ........................................................................................................ 4-5
4.2.3 Persistence Outline view .................................................................................................... 4-6
4.3 Preferences ................................................................................................................................... 4-7
4.3.1 Project Properties page – Persistence Options................................................................. 4-7
4.4 Dialogs .......................................................................................................................................... 4-7
4.4.1 Add Persistence dialog ....................................................................................................... 4-7
4.4.2 Generate Entities from Tables dialog................................................................................ 4-8
4.4.3 Edit Join Columns Dialog ................................................................................................... 4-8
4.5 Persistence perspective ............................................................................................................. 4-9
4.6 Icons and buttons ........................................................................................................................ 4-9
4.6.1 Icons .................................................................................................................................... 4-10
4.6.2 Buttons................................................................................................................................ 4-10
4.7 Dali Developer Documentation ............................................................................................. 4-11

iv
5 Tips and tricks

6 What’s new
6.1 Generate Persistent Entities from Tables wizard ................................................................... 6-1
6.2 Generate DDL from Entities wizard ........................................................................................ 6-1
6.3 Create and Manage the persistence.xml file ........................................................................... 6-2

7 Legal
7.1 About this content....................................................................................................................... 7-1

Index

v
vi
1
Getting started

This section provides information on getting started with the Dali OR


(object-relational) mapping tool.
■ Requirements and installation
■ Dali quick start
■ Dali basic tutorial
For additional information, please visit the Dali home page at:
http://www.eclipse.org/dali.

1.1 Requirements and installation


Before installing Dali, ensure that your environment meets the following minimum
requirements:
■ Eclipse 3.2 (http://www.eclipse.org/downloads)
■ Java Runtime Environment (JRE) 1.5 (http://java.com)
■ Eclipse Web Tools Platform (WTP) 1.5 (http://www.eclipse.org/webtools)
■ Java Persistence API (JPA) for Java EE 5. The reference implementation can be
obtained from:
https://glassfish.dev.java.net/downloads/persistence/JavaPersistence.html

Refer to http://www.eclipse.org/dali/gettingstarted_main.html for


additional installation information.
Review the Dali quick start and Dali basic tutorial to build your first Dali project.

1.2 Dali quick start


This section includes information to help you quickly start using Dali to create
relational mappings between Java persistent entities and database tables.
■ Creating a new project
■ Creating a Java persistent entity
■ Mapping an entity
The Dali basic tutorial contains detailed procedures for building you first Dali project.

Getting started 1-1


Dali quick start

1.2.1 Creating a new project


This quick start shows how to create a new Java Persistence Entity project. Before
creating the project, you should open the new Persistence perspective.
1. Switch to the new Persistence perspective to begin working with Java persistence
entities. Select Window > Open Perspective > Other. The Select Perspective
Dialog appears.

Figure 1–1 Selecting Persistence Perspective

2. On the Select Perspective dialog, select Java Persistence and click OK. The
workbench adds the Persistence Outline and Persistence Properties views.

Figure 1–2 Select Perspective Dialog

Now, we will create a new Java project.


1. Select File > New > Project. The New Project dialog appears.
2. On the New Project dialog, select Java > Java Project and click Next. The Create a
Java Project dialog appears.
3. On the Create a Java Project dialog, enter a Project name (such as QuickStart)
and click Next. The Java Settings page appears.

Note: You must configure your project’s JRE to use version 1.5 (or
higher). See "Requirements and installation" on page 1-1 for more
information.

1-2 Dali Object-Relational Mapping Tool User Guide


Dali quick start

4. On the Java Settings page click Finish. Eclipse adds the project to the workbench
and opens the Java perspective.
Finally, we will "add persistence" to the project.
1. Right-click the Java project in the Explorer and select Java Persistence > Add Java
Persistence. The Add Java Persistence Dialog appears.
2. On the Add Persistence dialog select a database connection (or click Add
Connection to create a new connection).

Note: You must be connected to the database before adding


persistence to the project. You will also need to create a table named
ADDRESS (you will add its columns later). Click Reconnect to
reconnect to an existing database.

Figure 1–3 Add Java Persistence Dialog

3. Click Configure the project build path to add the library or JARs that contain the
Java Persistence API (JPA) and entities to the project’s Java Build Path.
4. In the Packaging Settings area, enter the necessary information for your
persistence provider.

Getting started 1-3


Dali quick start

Figure 1–4 Add Java Persistence Dialog

For information on using a persistence.xml file for packaging your project, see
"Managing the persistence.xml file" on page 3-2.
5. Click Finish. Eclipse adds the persistence information to the project. You can now
work in the Persistence perspective.

Figure 1–5 Project in Package Explorer

Now that you have created a project with persistence, you can continue with Creating
a Java persistent entity.

1.2.2 Creating a Java persistent entity


This quick start shows how to create a new Java entity with persistence. We will create
an entity to associate with a database table.
1. Right-click the project in the Package Explorer and select New > Other. The Select
a Wizard dialog appears.
2. In the Select a Wizard dialog, select Java Persistence > Entity and click Next. The
Java Class page of the Create New Entity wizard appears.

1-4 Dali Object-Relational Mapping Tool User Guide


Dali quick start

Figure 1–6 Selecting the Java Persistence Entity Wizard

3. On the Java Class page, enter a package name (such as


quickstart.demo.model), class name (such as Address), and click Finish.

Figure 1–7 Creating a Java Class

Eclipse adds the new entity to the project and adds the @Entity annotation to the
class.

Getting started 1-5


Dali quick start

Figure 1–8 Address Entity

Eclipse also displays the Address entity in the Persistence Outline view:

Figure 1–9 Address Entity

After creating the entity, you must associate it with a database table.
1. Select the Address class in the Explorer view.
2. In the Persistence Properties view, notice that Dali has automatically associated
the ADDRESS database table with the entity because they are named identically.

Figure 1–10 Persistence Properties View for Address Entity

Now that you have created a persistent entity, you can continue with Mapping an
entity to map the entity’s fields to columns on the database table.

1.2.3 Mapping an entity


This quick start shows how to map fields in a Java persistent entity. Before beginning,
add the following fields to the Address class:
private Long id;
private String city;

1-6 Dali Object-Relational Mapping Tool User Guide


Dali quick start

private String country;


private String stateOrProvince;
private String postalCode;
private String street;

Eclipse updates the Address entity in the Persistence Outline view to show its fields:

Figure 1–11 Address Entity and Fields

You will also need to add the following columns to the ADDRESS database table:
NUMBER(10,0) ADDRESS_ID (primary key)
VARCHAR2(80) PROVINCE
VARCHAR2(80) COUNTRY
VARCHAR2(20) P_CODE
VARCHAR2(80) STREET
VARCHAR2(80) CITY

Now we are ready to map each fields in the Address class to a column in the database
table.
1. Select the id field in the Persistence Outline view.
2. In the Persistence Properties view:
■ For the Map As field, select ID
■ For the Column field, select ADDRESS_ID.

Figure 1–12 Persistence Properties View for addressId Field

Eclipse adds the following annotations to the Address entity:


@Id
@Column(name="ADDRESS_ID")

Getting started 1-7


Dali basic tutorial

3. Map each of the following fields (as Basic mappings) to the appropriate database
column:

Field Map As Database Column


city Basic CITY
country Basic COUNTRY
postalCode Basic P_CODE
provinceOrState Basic PROVINCE
street Basic STREET

Notice that Dali will automatically map some fields to the correct database column
(such as the city field to the CITY column) if the names are identical.
Refer to the Dali basic tutorial to map a complete object model using basic and
relational mappings.

1.3 Dali basic tutorial


In this tutorial, you will use Dali to map the object model of a company’s HR
application to track its employees. Figure 1–13 illustrates the object model for the
tutorial.

Figure 1–13 Tutorial Object Model

1.3.1 Generate the tutorial database schema


The tutorial application uses three database tables to store each employee’s
information: EMPLOYEE, ADDRESS and PHONE. Table 1–1 describes the columns
for each table.
You can download SQL scripts to build and populate the database tables with sample
data from http://www.eclipse.org/dali/docs/dbscripts.zip.

1-8 Dali Object-Relational Mapping Tool User Guide


Dali basic tutorial

Table 1–1 Tutorial Database Schema


Table Column Type Details
EMPLOYEE EMP_ID NUMBER(15) Primary Key
F_NAME VARCHAR(40)
L_NAME VARCHAR(40)
ADDR_ID NUMBER(15) Foreign Key, references
ADDRESS.ADDRES_ID
VERSION NUMBER(15)
ADDRESS ADDRESS_ID NUMBER(15) Primary Key
PROVINCE VARCHAR(80)
COUNTRY VARCHAR(80)
STREET VARCHAR(80)
P_CODE VARCHAR(20)
CITY VARCHAR(80)
PHONE EMP_ID NUMBER(15) Foreign Key, reference to
EMPLOYEE.EMP_ID
AREA_CODE VARCHAR(3)
P_NUMBER VARCHAR(7) Primary key
TYPE VARCHAR(15)

1.3.1.1 Create a database connection


After creating the database you will need to create a database connection to use with
the tutorial application. An active database connection is required to complete tutorial
application.
Use the New Connection wizard to create a database connection.

Figure 1–14 Database Explorer

Now you’re ready to Create a Java project.

1.3.2 Create a Java project


In order to begin, you must create a new Java project.

Getting started 1-9


Dali basic tutorial

1. Select File > New > Project. The New Project dialog appears.
2. On the New Project dialog, select Java > Java Project and click OK. The Create a
Java Project dialog appears.
3. On the Create a Java Project dialog, enter Employee as the Project name and click
Finish. Eclipse adds the project to the workbench and opens the Java perspective.

1.3.2.1 Add persistence to the project


Use this procedure to add persistence to the Employee project.
1. Right-click the Employee project in the Explorer and select Java Persistence >
Add Java Persistence. The Add Java Persistence Dialog appears.
2. In the Database Settings area select a database connection that you created earlier
(see "Create a database connection").
You must be connected to the database before adding persistence to the project.
3. Click Configure the project build path to add the library or JARs that contain the
Java Persistence API (JPA) and entities to the project’s Java Build Path.
4. In the Packaging Settings area select the Create persistence.xml option and
complete the following fields:
■ Persistence Version: 1.0
■ Persistence Provider: Enter the name of the JPA provider that you selected in
step 3 (such as TopLink Essentials).
■ Persistence Unit Name: Dali Tutorial

Figure 1–15 Add Persistence Dialog

5. Click Finish. You can now work in the Persistence perspective.


6. Select Window > Open Perspective > Other. The Select Perspective dialog
appears.

1-10 Dali Object-Relational Mapping Tool User Guide


Dali basic tutorial

7. Select Persistence and click OK. The Persistence Outline and Properties views
appear.

Figure 1–16 Persistence Perspective

The next step is to Create persistent Java entities.

1.3.3 Create persistent Java entities


The Tutorial Object Model contains three entities: Employee, Address, and
PhoneNumber. Use this procedure to add the entities to the project.
1. Right-click the Employee project in the Package Explorer and select New > Other.
The Select a Wizard dialog appears.
2. In the Select a Wizard dialog, select Java Persistence > Entity and click Next. The
Java Class page of the Create New Java Persistence Entity wizard appears.
3. On the Java Class page, enter a package name (such as dali.tutorial.model),
class name (such as Employee), and click Finish.
Eclipse adds the Employee entity to the Package Explorer and adds the @Entity
annotation to the class. Repeat this procedure to add the PhoneNumber and Address
entities.
Notice that the Problems view reports several errors for each entity. We’ll address
these shortly.

Getting started 1-11


Dali basic tutorial

1.3.3.1 Add fields to the entities


Before mapping the entities to the database, you must add the necessary fields to each
entity.
1. Add the following fields to the Employee entity:
private Long id;
private String firstNname;
private String lastName;
private String address;
private List<PhoneNumber> phoneNumbers;
private Long version;

2. Import java.util.List.
3. Generate Getters and Setters for each field.
4. Add the following fields to the Address entity:
private Long id;
private String street;
private String city;
private String stateOrProvince;
private String country;
private String postalCode;

5. Add the following fields to the PhoneNumber entity:


private String type;
private String areaCode;
private String number;
private Employee owner;

1.3.3.2 Associate the entity with a database table


Now you must associate each entity with its primary database table.
1. Select the Employee class in the Explorer view.
2. In the Persistence Properties view, select General tab.
3. On the General tab, notice that Dali has automatically selected the EMPLOYEE
table as the table name.

1-12 Dali Object-Relational Mapping Tool User Guide


Dali basic tutorial

Figure 1–17 Persistence Properties View for the Employee Entity

By default, Dali attempts to associate each entity with a similarly named database
table. Notice that although you have not explicitly associated the Address entity yet,
there is no error in the Problems view because the entity name, Address, is identical to
the table name (ADDRESS).
For the PhoneNumber entity, however, there is an error. This is because the entity
name (PhoneNumber) is different than the database table (PHONE). You must
explicitly associate the entity with the PHONE table. Dali adds the
@Table(name="PHONE") annotation to the entity.
Now you are ready to Create OR mappings.

1.3.4 Create OR mappings


Now you’re ready to map the attributes of each persistent entity to columns in the
appropriate database table. For the tutorial application, you will use the following
mapping types:
■ ID mappings
■ Basic mappings
■ One-to-one mappings
■ Many-to-one mappings
■ One-to-many mappings
■ Version mappings

1.3.4.1 Create ID mappings


Use an ID Mapping to specify the primary key of an entity. Each persistent entity
must have an ID. Notice that the Problems view reports that each entity is missing an
ID.
1. Select the Employee entity in the Package Explorer view.
2. Expand the Employee entity in the Persistence Outline view and select the id field.
The Persistence Properties view (for attributes) displays the properties for the
field.
3. In the Map As field, select ID.

Getting started 1-13


Dali basic tutorial

Figure 1–18 ID Mapping for emp_id Field

4. Use this table to complete the remaining fields on the General tab in the
Persistence Properties view.

Property Description
Map As Defines this mapping as an ID Mapping. Dali adds the @Id
annotation to the entity.
Column The database column for the primary key of the table associated
with the entity. Select EMP_ID.
Because the database column (EMP_ID) is named differently
than the entity field (id), Dali adds the @Column(name="EMP_
ID") annotation.

5. Leave all other fields on the tab as their defaults. Click the PK Generation tab.

Figure 1–19 Primary Key Generation for emp_id Field

6. Use this table to complete the remaining fields on the General tab in the
Persistence Properties view.

Property Description
Generated Value These fields define how the primary key is generated.
Strategy For the tutorial project, use the Auto option.
Generator Name Leave this field blank.

1-14 Dali Object-Relational Mapping Tool User Guide


Dali basic tutorial

In the Persistence Outline, the id field is identified as the primary key by the following
icon:

Figure 1–20 Persistence Outline for Employee Entity

Repeat this procedure to map the following primary keys (as shown in Table 1–1,
" Tutorial Database Schema"):
■ The id field of the Address entity to the ADDRESS_ID column of the ADDRESS
table.
■ The number field of the PhoneNumber entity to the P_NUMBER column of the
PHONE table.

1.3.4.2 Create basic mappings


Use a Basic Mapping to map an attribute directly to a database column. In the Tutorial
Object Model, the firstName field of the Employee class maps directly to the F_NAME
column of the EMPLOYEE database table.
1. Select the Employee entity in the Package Explorer view.
2. In the Persistence Outline view, select the firstName field of the Employee entity.
The Persistence Properties view (for attributes) displays the properties for the
field.
3. In the Map As field, select Basic. In the Column field, select F_NAME.

Figure 1–21 Basic Mapping for firstName

Dali adds the @Column(name="F_NAME") annotation to the entity. In the Persistence


Outline, the firstName field is identified as a basic mapping as shown in the following
figure:

Getting started 1-15


Dali basic tutorial

Figure 1–22 Persistence Outline for Employee Entity

Repeat this procedure to map each of the following fields as Basic mappings:
■ Employee entity
– lastName field to L_NAME column
■ Address Entity
– city field to CITY column
– country field to COUNTRY column
– postalCode field to P_CODE column
– stateOrProvice field to PROVINCE column
– street field to STREET column

Note: Because the city, country, and street fields are named
identically to their database columns, Dali automatically maps the
fields; no annotations are required.

■ Phone Entity
– areaCode field to AREA_CODE column
– type field to TYPE column

Note: Because the type field is named identically to its database


column, Dali automatically maps the field. No annotation is required.

1.3.4.3 Create one-to-one mappings


Use a One-to-One Mapping to define a relationship from an attribute to another class,
with one-to-one multiplicity to a database column. In the Tutorial Object Model, the
address field of the Employee class has a one-to-one relationship to the Address class;
each employee may have a single address.
1. Select the Employee entity in the Package Explorer view.
2. In the Persistence Outline view, select the address field of the Employee entity.
The Persistence Properties view (for attributes) displays the properties for the
field.
3. In the Map As field, select One-to-One.

1-16 Dali Object-Relational Mapping Tool User Guide


Dali basic tutorial

Figure 1–23 One-to-one Mapping for address

4. For the Target Entity, click Browse and select the Address persistent entity. Dali
adds the
@OneToOne(targetEntity=dali.tutorial.model.Address.class)
entity to the class.
Leave the other fields with their default values.
5. Select the Join Columns tab specifies the relationship between the Employee and
Address entities. Because you had to explicitly define the ID field for the Address
entity in its ID mapping, you will need to edit the default join relationship.
6. Select the Override Default option.
7. Select the address_ADDRESS_ID -> ADDRESS_ID relationship in the Join
Columns area and click Edit.
8. In the Edit Join Column dialog, select the following options and click OK.
■ Name: ADDR_ID (from the EMPLOYEE table)
■ Referenced Column Name: ADDRESS_ID (from the ADDRESS table)

Figure 1–24 Editing Join Column for Address Mapping

In the Persistence Outline, the address field is identified as a one-to-one mapping, as


shown in the following figure:

Figure 1–25 Persistence Outline for Employee Entity

Getting started 1-17


Dali basic tutorial

1.3.4.4 Create one-to-many mappings


Use a One-to-Many Mapping to define a relationship from an attribute to another
class, with one-to-many multiplicity to a database column. In the Tutorial Object
Model, the phoneNumbers field of the Employee class has a one-to-many relationship
to the Phone class; each employee may have many phone numbers.
1. Select the Employee entity in the Package Explorer view.
2. In the Persistence Outline view, select the phoneNumber field of the Employee
entity. The Persistence Properties view (for attributes) displays the properties for
the field.
3. In the Map As field, select One-to-Many.

Figure 1–26 One-to-many Mapping for phoneNumbers

4. On the General tab, select PhoneNumber as the Target Entity. Leave the other
fields with their default values.
5. On the Join Table tab, notice that Dali has selected the correct joins, based on the
foreign key associations in the database tables.
In the Persistence Outline, the phoneNumbers field is identified as a one-to-many
mapping as shown in the following figure:

Figure 1–27 Persistence Outline for Employee Entity

1.3.4.5 Create many-to-one mappings


Use a May-to-One Mapping to define a relationship from an attribute to another class,
with many-to-one multiplicity to a database column. In the Tutorial Object Model, the
owner field of the PhoneNumber class has a one-to-many relationship to the
Employee class; there are many phone numbers that each employee may have.
This is the "back mapping" of the one-to-many mapping you previously defined.
1. Select the PhoneNumber entity in the Package Explorer view.

1-18 Dali Object-Relational Mapping Tool User Guide


Dali basic tutorial

2. In the Persistence Outline view, select the owner field of the PhoneNumber entity.
The Persistence Properties view (for attributes) displays the properties for the
field.
3. In the Map As field, select Many to One.

Figure 1–28 Many to One Mapping for owner

4. Leave the other fields with their default values. Dali correctly completes the
information based on the database structure and previously defined mappings.
5. Select the Join Columns tab specifies the relationship between the PhoneNumber
and Employee entities. Because you had to explicitly define the ID field for the
Employee entity in its ID mapping, you will need to edit the default join
relationship.
6. Select the Override Default option.
7. Select the owner_EMP_ID -> EMP_ID relationship in the Join Columns area and
click Edit.
8. In the Edit Join Column dialog, select the following options and click OK.
■ Name: EMP_ID (from the PHONE table)
■ Referenced Column Name: EMP_ID (from the EMPLOYEE table)
In the Persistence Outline, the owner field is identified as a many-to-one mapping as
shown in the following figure:

Figure 1–29 Persistence Outline for PhoneNumber Entity

1.3.4.6 Create version mappings


Use a Version Mapping to specify the database field used by a persistent entity for
optimistic locking.
1. Select the Employee entity in the Package Explorer view.

Getting started 1-19


Dali basic tutorial

2. In the Persistence Outline view, select the version field of the Employee entity.
The Persistence Properties view (for attributes) displays the properties for the
field.
3. In the Map As field, select Version.

Figure 1–30 Version Mapping for version

Dali automatically selects the Version column in the EMPLOYEE database table. In the
Persistence Outline, the Version field is identified as a version mapping, as shown in
the following figure:

Figure 1–31 Persistence Outline for Employee Entity

Congratulations! All of the entities have been successfully mapped.

1-20 Dali Object-Relational Mapping Tool User Guide


2
Concepts

This section contains an overview of concepts you should be familiar with when using
Dali to create mappings for Java persistent entities.
■ Understanding Java persistence
■ Understanding OR mappings
■ Understanding JSR220: EJB 3.0
In addition to these sections, you should review the following resources for additional
information:
■ Eclipse Dali project: http://www.eclipse.org/dali
■ Eclipse Web Tools Platform project: http://www.eclipse.org/webtools
■ JSR 220 EJB 3.0 specification: http://www.jcp.org/en/jsr/detail?id=220

2.1 Understanding Java persistence


Persistence refers to the ability to store objects in a database and use those objects with
transactional integrity. In a J2EE application, data is typically stored and persisted in
the data tier, in a relational database.
Entity beans are enterprise beans that contain persistent data and that can be saved in
various persistent data stores. The entity beans represent data from a database; each
entity bean carries its own identity. Entity beans can be deployed using
application-managed persistence or container-managed persistence.

2.2 Understanding OR mappings


The Dali OR (object-relational) Mapping Tool allows you to describe how your entity
objects map to the data source (or other objects). This approach isolates persistence
information from the object model–developers are free to design their ideal object
model, and DBAs are free to design their ideal schema.
These mappings transform an object data member type to a corresponding relational
database data source representation. These OR mappings can also transform object
data members that reference other domain objects stored in other tables in the
database and are related through foreign keys.
You can use these mappings to map simple data types including primitives (such as
int), JDK classes (such as String), and large object (LOB) values. You can also use
them to transform object data members that reference other domain objects by way of
association where data source representations require object identity maintenance
(such as sequencing and back references) and possess various types of multiplicity and

Concepts 2-1
Understanding JSR220: EJB 3.0

navigability. The appropriate mapping class is chosen primarily by the cardinality of


the relationship.

2.3 Understanding JSR220: EJB 3.0


The Java 2 Enterprise Edition(J2EE) Enterprise JavaBeans (EJB) are a component
architecture that you use to develop and deploy object-oriented, distributed,
enterprise-scale applications. An application written according to the Enterprise
JavaBeans architecture is scalable, transactional, and secure.
The purpose of EJB 3.0 (JSR220) improves the EJB architecture by reducing its
complexity through the use of metadata (annotations) and specifying programmatic
defaults of that metadata.

2.3.1 The persistence.xml file


The EJB 3.0 specification requires the use of a persistence.xml file for deployment.
This file defines the database and entity manager options, and may contain more than
one persistence unit. Dali includes a Persistence XML Editor to help create and
maintain this information. See "Managing the persistence.xml file" on page 3-2 for
more information.

2-2 Dali Object-Relational Mapping Tool User Guide


3
Tasks

This section includes detailed step-by-step procedures for accessing the Dali OR
mapping tool functionality.
■ Adding persistence to a Java project
■ Managing the persistence.xml file
■ Adding persistence to a class
■ Creating a new Java persistent entity
■ Specifying entity inheritance
■ Mapping an entity
■ Generating entities from tables
■ Generating tables (DDL scripts) from entities
■ Validating mappings and reporting problems
■ Modifying persistent project properties

3.1 Adding persistence to a Java project


Use this procedure to add persistence to an existing project:
1. Right-click the project in the Package Explorer and select Java Persistence > Add
Java Persistence.

Figure 3–1 Adding Persistence to a Project

Tasks 3-1
Managing the persistence.xml file

2. Complete the fields in the Add Persistence dialog to select a database connection
and persistence packaging options.
■ To create a new database connection, click Add Connections use the New
Connection wizard. To reconnect to an existing connection, click Reconnect.

Note: You must have a defined database connection (and be


connected) to add persistence to a project.

■ To add the libraries that contain the JPA (Java Persistence API), click
Configure the project build path and use the Java Build Path page of the
project's Properties dialog.
■ To package your persistent project, select the Create persistence.xml option
and complete the fields in the Packaging Settings area. See "Managing the
persistence.xml file" on page 3-2 for more information.

Figure 3–2 Add Java Persistence Dialog

3. Click Finish. You should now open the Persistence perspective.

3.2 Managing the persistence.xml file


When adding persistence to a project (see "Adding persistence to a Java project") you
can also create the persistence.xml file. Complete the Packaging Settings fields on
the Add Persistence dialog.
Use this procedure to define the persistence.xml file:
1. Right-click the project in the Package Explorer and select Java Persistence > Add
Java Persistence.

3-2 Dali Object-Relational Mapping Tool User Guide


Managing the persistence.xml file

Figure 3–3 Adding Persistence to a Project

2. Complete the Database Settings fields on the Add Persistence dialog to select a
database connection to use with the persistent project.
3. Select the Create persistence.xml option and complete the fields in the Packaging
Settings area to create the persistence.xml file.
■ Persistence Version – Persistence version to use.
■ Persistence Provider – Name of the persistence provider’s
javax.persistence.spi.PersistenceProvider class.
■ Persistence Unit Name – Name of the persistence unit.

Figure 3–4 Add Java Persistence Dialog

4. Click Finish. You should now open the Persistence perspective.


Eclipse creates the META-INF\persistence.xml file in your project’s directory:
<?xml version="1.0" encoding="UTF-8"?>

Tasks 3-3
Managing the persistence.xml file

<persistence version="<PERSISTENCE_VERSION>"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="<PERSISTENCE_UNIT_NAME>">
<provider="<PERSISTENCE_PROVIDER>" />
</persistence-unit>
</persistence>

3.2.1 Working with persistence.xml file


You can work with the persistence.xml by using the Persistence XML Editor.
Use this procedure to work with the persistence.xml file:
1. Right-click the persistence.xml file in the Package Explorer and select Open
With > Persistence XML Editor.

Figure 3–5 Opening the Persistence XML Editor

2. Use the Persistence XML Editor to edit the persistence.xml file.

Figure 3–6 Persistence XML Editor

3-4 Dali Object-Relational Mapping Tool User Guide


Adding persistence to a class

3.2.2 Synchronizing classes


As you work with the classes in your Java project, you will need to update the
persistence.xml file to reflect the changes.
Use this procedure to synchronize the persistence.xml file:
1. Right-click the persistence.xml file in the Package Explorer and select Java
Persistence > Synchronize Classes.

Figure 3–7 Synchronizing the persistence.xml File

Dali adds the necessary <class> elements to the persistence.xml file.


2. Use the Persistence XML Editor to continue editing the persistence.xml file.

3.3 Adding persistence to a class


You can make a Java class into one of the following persistent types:
■ Persistent entity
■ Embeddable
■ Mapped superclass
You can also add persistence when creating a new Java class. See "Creating a new Java
persistent entity" on page 3-8 for more information.

3.3.1 Persistent entity


An Entity is a persistent domain object.
An entity can be:
■ Abstract or concrete classes. Entities may also extend non-entity classes as well as
entity classes, and non-entity classes may extend entity classes.
An entity must have:
■ A no-arg constructor (public or protected); the entity class may have other
constructors as well.
Each persistent entity must be mapped to a database table and contain a primary key.
Persistent entities are identified by the @Entity annotation.
Use this procedure to add persistence to an existing entity:

Tasks 3-5
Adding persistence to a class

1. Right-click the class in the Package Explorer and select Java Persistence > Make
Java Persistence Entity.

Figure 3–8 Adding Persistence to a Class

2. In the Persistence Properties view, use the Map As drop-list to select Entity.

Figure 3–9 Selecting Entity Persistence

3. Complete the remaining Persistence Properties view (for entities).

3.3.2 Embeddable
An Embedded class is a class whose instances are stored as part of an owning entity; it
shares the identity of the owning entity. Each field of the embedded class is mapped to
the database table associated with the owning entity.
To override the mapping information for a specific subclass, use the
@AttributeOverride annotation for that specific class.
An embeddable entity is identified by the @Embeddable annotation.
Use this procedure to add embeddable persistence to an existing entity:
1. Right-click the class in the Package Explorer and select Java Persistence > Make
Java Persistence Entity.

3-6 Dali Object-Relational Mapping Tool User Guide


Adding persistence to a class

Figure 3–10 Adding Persistence to a Class

2. In the Persistence Properties view, use the Map As drop-list to select Embeddable.

Figure 3–11 Selecting Embeddable Persistence

3. Complete the remaining Persistence Properties view (for entities).

3.3.3 Mapped superclass


An entities that extend a Mapped Superclass class inherit the persistent state and
mapping information from a superclass. You should use a mapped superclass to
define mapping information that is common to multiple entity classes.
A mapped superclass can be:
■ Abstract or concrete classes
A mapped superclass cannot be:
■ Be queried or passed as an argument to Entity-Manager or Query operations
■ Be the target of a persistent relationship
A mapped superclass does not have a defined database table. Instead, its mapping
information is derived from its superclass. To override the mapping information for a
specific subclass, use the @AttributeOverride annotation for that specific class.
A mapped superclass is identified by the @MappedSuperclass annotation.
Use this procedure to add Mapped Superclass persistence to an existing entity:
1. Right-click the class in the Package Explorer and select Persistence > Make Java
Persistence Entity.

Tasks 3-7
Creating a new Java persistent entity

Figure 3–12 Adding Persistence to a Class

2. In the Persistence Properties view, use the Map As drop-list to select Mapped
Superclass.

Figure 3–13 Selecting Mapped Superclass Persistence

3. Complete the remaining Persistence Properties view (for entities).

3.4 Creating a new Java persistent entity


Use this procedure to create a new persistent entity by using the Java Persistent Entity
wizard.
1. Right-click the project in the Package Explorer and select New > Other.
2. In the Select a Wizard dialog, select Java Persistence > Entity and click Next.

Figure 3–14 Selecting the Java Persistence Entity Wizard

3-8 Dali Object-Relational Mapping Tool User Guide


Specifying entity inheritance

3. On the Java Class page, complete the information for the new class, and click
Next.
Eclipse adds the new persistent entity to the project. Use the Persistence Properties
view (for entities) to further define the entity.

3.5 Specifying entity inheritance


An entity may inherit properties from other entities. You can specify a specific strategy
to use for inheritance.
Use this procedure to specify inheritance (@Inheritance) for an existing entity
(@Entity):
1. Select the entity in the Package Explorer.
2. In the Persistence Properties view, click the Inheritance tab.

Figure 3–15 Specifying Inheritance

3. In the Strategy list, select one of the following the inheritance strategies:
■ A single table (default)
■ Joined table
■ One table per class
4. Use the following table to complete the remaining fields on the tab. See
"Inheritance tab" on page 4-2 for additional details.

Property Description Default


Discriminator Name of the discriminator column when using a
Column Single or Joined inheritance strategy.
This field corresponds to the
@DiscriminatorColumn annotation.
Discriminator Type Set the discriminator type to Char or Integer String
(instead of its default: String). The
Discriminator Value must conform to this type.

Tasks 3-9
Mapping an entity

Property Description Default


Discriminator Value Specify the discriminator value used to
differentiate an entity in this inheritance
hierarchy. The value must conform to the
specified Discriminator Type.
This field corresponds to the
@DiscriminatorValue annotation.
Override Default Use this field to specify custom primary key join
columns.
This field corresponds to the
@PrimaryKeyJoinClumn annotation.

Eclipse adds the following annotations the entity field:


@Inheritance(strategy=InheritanceType.<INHERITANCE_STRATEGY>)
@DiscriminatorColumn(name="<DISCRIMINATOR_COLUMN>",
discriminatorType=<DISCRIMINATOR_TYPE>)
@DiscriminatorValue(value-"<DISCRIMINATOR_VALUE>")
@PrimaryKeyJoinColumn(name="<JOIN_COLUMN_NAME>",
referencedColumnName = "<REFERENCED_COLUMN_NAME>")

The following figures illustrates the different inheritance strategies.

Figure 3–16 Single Table Inheritance

Figure 3–17 Joined Table Inheritance

3.6 Mapping an entity


Dali supports the following mapping types for Java persistent entities:

3-10 Dali Object-Relational Mapping Tool User Guide


Mapping an entity

■ Basic mapping
■ Embedded mapping
■ Embedded ID mapping
■ ID mapping
■ Many-to-many mapping
■ Many-to-one mapping
■ One-to-many mapping
■ One-to-one mapping
■ Transient mapping
■ Version mapping

3.6.1 Basic mapping


Use a Basic Mapping to map an attribute directly to a database column. Basic
mappings may be used only with the following attribute types:
■ Java primitive types and wrappers of the primitive types
■ java.lang.String, java.math.BigInteger
■ java.math.BigDecimal
■ java.util.Date
■ java.util.Calendar, java.sql.Date
■ java.sql.Time
■ java.sql.Timestamp
■ byte[]
■ Byte[]
■ char[]
■ Character[]
■ enums
■ any other type that implements Serializable
To create a basic mapping:
1. In the Persistence Outline view, select the field to map. The Persistence Properties
view (for attributes) displays the properties for the selected field.
2. In the Map As field, select Basic.
3. Use this table to complete the remaining fields on the Persistence Properties view.

Property Description Default


Map As Defines this mapping as a Basic Basic
Mapping.
This field corresponds to the
@Basic annotation.

Tasks 3-11
Mapping an entity

Property Description Default


Column The database column (and its table) By default, the Column is assumed
mapped to the entity attribute. See to be named identically to the
"Column" on page 4-3 for details. attribute and always included in the
INSERT and UPDATE statements.
■ Name – Name of the database
column.
■ Table – Name of the database
table.
■ Insertable – Specify if the
column is always included in
SQL INSERT statements.
■ Updatable – Specify if the
column is always included in
SQL UPDATE statements.
Fetch Type Defines how data is loaded from the Eager
database. See "Fetch Type" on
page 4-4 for details.
■ Eager
■ Lazy
Optional Specifies if this field is can be null. Yes
Temporal Specifies the type of data. See
"Temporal" on page 4-4 for details.
■ Date
■ Time
■ Timestamp

Eclipse adds the following annotations to the field:


@Column(name="<COLUMN_NAME>", table="<COLUMN_TABLE>",
insertable=<INSERTABLE>, updatable=<UPDATABLE>)
@Basic(fetch=FetchType.<FETCH_TYPE>, optional = <OPTIONAL>)
@Temporal(TemporalType.<TEMPORAL>)

3.6.2 Embedded mapping


Use an Embedded Mapping to specify a persistent field or property of an entity
whose value is an instance of an embeddable class.
1. In the Persistence Outline view, select the field to map. The Persistence Properties
view (for attributes) displays the properties for the selected field.
2. In the Map As field, select Embedded.
3. Use this table to complete the remaining fields on the Persistence Properties view.

Property Description Default


Map As Defines this mapping as a Embedded. Embedded
This field corresponds to the
@Embedded annotation.
Attribute Specify to override the default
Overrides mapping of an entity’s attribute.

3-12 Dali Object-Relational Mapping Tool User Guide


Mapping an entity

Property Description Default


Columns The database column (and its table) By default, the Column is assumed
mapped to the entity attribute. See to be named identically to the
"Column" on page 4-3 for details. attribute and always included in
the INSERT and UPDATE
■ Name – Name of the database
statements.
column.
■ Table – Name of the database
table.
■ Insertable – Specify if the column
is always included in SQL
INSERT statements.
■ Updatable – Specify if the column
is always included in SQL
UPDATE statements.

Eclipse adds the following annotations to the field:


@Embedded

3.6.3 Embedded ID mapping


Use an Embedded ID Mapping to specify the primary key of an embedded ID. These
mappings may be used with a Embeddable entities.
1. In the Persistence Outline view, select the field to map. The Persistence Properties
view (for attributes) displays the properties for the selected field.
2. In the Map As field, select Embedded Id.
3. Use this table to complete the remaining fields on the Persistence Properties view.

Property Description Default


Map As Defines this mapping as a Embedded Embedded Id
Id.
This field corresponds to the
@EmbeddedId annotation.

Eclipse adds the following annotations to the field:


@EmbeddedId

3.6.4 ID mapping
Use an ID Mapping to specify the primary key of an entity. ID mappings may be used
with a Persistent entity or Mapped superclass. Each Persistent entity must have an ID
mapping.
1. In the Persistence Outline view, select the field to map. The Persistence Properties
view (for attributes) displays the properties for the selected.
2. In the Map As field, select ID.
3. Use this table to complete the remaining fields on General tab in the Persistence
Properties view.

Tasks 3-13
Mapping an entity

Property Description Default


Map As Defines this mapping as an ID ID
Mapping.
This field corresponds to the @Id
annotation.
Column The database column (and its table) By default, the Column is
mapped to the entity attribute. See assumed to be named
"Column" on page 4-3 for details. identically to the attribute and
always included in the INSERT
■ Name – Name of the database
and UPDATE statements.
column.
■ Table – Name of the database
table.
■ Insertable – Specify if the column
is always included in SQL
INSERT statements.
■ Updatable – Specify if the column
is always included in SQL
UPDATE statements.
Temporal Specifies the type of data. See
"Temporal" on page 4-4 for details.
■ Date
■ Time
■ Timestamp

4. Use this table to complete the fields on PK Generation tab in the Persistence
Properties view.

Property Description Default


Primary Key These fields define how the primary
Generation key is generated.
Strategy See "Primary Key Generation" on Auto
page 4-6 for details.
■ Auto
■ Sequence
■ Identity
■ Table
Generator Name Name of the primary key generator
specified in the Strategy

Additional fields will appear on the PK Generation tab, depending on the selected
Strategy. See "Persistence Properties view (for attributes)" on page 4-3 for additional
information.
Eclipse adds the following annotations to the field:
@Id
@Column(name="<COLUMN_NAME>", table="<TABLE_NAME>", insertable=<INSERTABLE>,
updatable=<UPDATABLE>)
@Temporal(TemporalType.<TEMPORAL>)
@GeneratedValue(strategy=GeneratorType.<STRATEGY>, generator="<GENERATOR_NAME>")
@TableGenerator(name="<TABLE_GENERATOR_NAME>", table = "<TABLE_GENERATOR_TABLE>",
pkColumnName = "<TABLE_GENERATOR_PK>",

3-14 Dali Object-Relational Mapping Tool User Guide


Mapping an entity

valueColumnName = "<TABLE_GENERATOR_VALUE_COLUMN>",
pkColumnValue = "<TABLE_GENERATOR_PK_COLUMN_VALUE>")
@SequenceGenerator(name="<SEQUENCE_GENERATOR_NAME>",
sequenceName="<SEQUENCE_GENERATOR_SEQUENCE>")

3.6.5 Many-to-many mapping


Use a Many-to-Many Mapping to define a many-valued association with
many-to-many multiplicity. A many-to-many mapping has two sides: the owning side
and non-owning side. You must specify the join table on the owning side. For
bidirectional mappings, either side may be the owning side.
1. In the Persistence Outline view, select the field to map. The Persistence Properties
view (for attributes) displays the properties for the selected.
2. In the Map As field, select Many-to-Many.
3. Use this table to complete the fields on the General tab of the Persistence
Properties view.

Property Description Default


Target Entity The entity to which this attribute is null
mapped.
You do not need to explicitly specify
the target entity, since it can be
inferred from the type of object
being referenced.
Cascade Type See "Cascade Type" on page 4-4 for Default
details.
■ Default
■ All
■ Persist
■ Merge
■ Remove
Fetch Type Defines how data is loaded from the Eager
database. See "Fetch Type" on
page 4-4 for details.
■ Eager
■ Lazy
Mapped By The database field that owns the
relationship.
Order By Specify the default order for objects Primary key
returned from a query. See "Order
By" on page 4-4 for details.
■ Primary key

4. Use this table to complete the fields on the Join Table tab tab in the Persistence
Properties view.

Tasks 3-15
Mapping an entity

Property Description Default


Name Name of the join table that contains the You must specify the join table on
foreign key column. the owning side.
By default, the name is assumed to
be the primary tables associated
with the entities concatenated with
an underscore.
Join Columns Select Override Default, then Add, By default, the name is assumed to
Edit, or Remove the join columns. be the primary tables associated
with the entities concatenated with
an underscore.
Inverse Join Select Override Default, then Add, By default, the mapping is
Columns Edit, or Remove the join columns. assumed to have a single join.

5. To add a new Join or Inverse Join Column, click Add.


To edit an existing Join or Inverse Join Column, select the field to and click Edit.
Eclipse adds the following annotations to the field:
@JoinTable(joinColumns=@JoinColumn(name="<JOIN_COLUMN>"),
name = "<JOIN_TABLE_NAME>")
@ManyToMany(cascade=CascadeType.<CASCADE_TYPE>, fetch=FetchType.<FETCH_TYPE>,
targetEntity=<TARGET_ENTITY>, mappedBy = "<MAPPED_BY>")
@OrderBy("<ORDER_BY>")

3.6.6 Many-to-one mapping


Use a Many-to-One mapping to defines a single-valued association to another entity
class that has many-to-one multiplicity.
1. In the Persistence Outline view, select the field to map. The Persistence Properties
view (for attributes) displays the properties for the selected.
2. In the Map As field, select Many-to-One.
3. Use this table to complete the fields on the General tab in the Persistence
Properties view.

Property Description Default


Target Entity The entity to which this attribute is null
mapped.
You do not need to explicitly specify
the target entity, since it can be
inferred from the type of object
being referenced.
Fetch Type Defines how data is loaded from the Eager
database. See "Fetch Type" on
page 4-4 for details.
■ Eager
■ Lazy

3-16 Dali Object-Relational Mapping Tool User Guide


Mapping an entity

Property Description Default


Cascade Type See "Cascade Type" on page 4-4 for Default
details.
■ Default
■ All
■ Persist
■ Merge
■ Remove
Optional Specifies if this field is can be null. Yes

4. Use this table to complete the fields on the Join Columns tab tab in the Persistence
Properties view.

Property Description Default


Join Column Specify a mapped column for joining By default, the mapping is assumed
an entity association. This field to have a single join.
corresponds to the @JoinColum
attribute.
Select Override Default, then Add,
Edit, or Remove the join columns.

Eclipse adds the following annotations to the field:


@JoinTable(joinColumns=@JoinColumn(name="<JOIN_COLUMN>"),
name = "<JOIN_TABLE_NAME>")
@ManyToOne(targetEntity=<TARGET_ENTITY>, fetch=<FETCH_TYPE>,
cascade=<CASCADE_TYPE>)

3.6.7 One-to-many mapping


Use a One-to-Many Mapping to define a relationship with one-to-many multiplicity.
1. In the Persistence Outline view, select the field to map. The Persistence Properties
view (for attributes) displays the properties for the selected.
2. In the Map As field, select One-to-many.
3. Use this table to complete the fields on the General tab in the Persistence
Properties view.

Property Description Default


Target Entity The entity to which this attribute is
mapped.
Cascade Type See "Cascade Type" on page 4-4 for
details.
■ Default
■ All
■ Persist
■ Merge
■ Remove

Tasks 3-17
Mapping an entity

Property Description Default


Fetch Type Defines how data is loaded from the Eager
database. See "Fetch Type" on page 4-4
for details.
■ Eager
■ Lazy
Mapped By The database field that owns the
relationship.
Order By Specify the default order for objects Primary key
returned from a query. See "Order By"
on page 4-4 for details.
■ Primary key

4. Use this table to complete the fields on the Join Table tab in the Persistence
Properties view.

Property Description Default


Name Name of the join table By default, the name is assumed to
be the primary tables associated
with the entities concatenated with
an underscore.
Join Columns Specify two or more join columns (that
is, a primary key).
Inverse Join The join column on the owned (or
Columns inverse) side of the association: the
owned entity’s primary key column.

Eclipse adds the following annotations to the field:


@OneToMany(targetEntity=<TARGET_ENTITY>)
@Column(name="<COLUMN>")

@OneToMany(targetEntity=<TARGET_ENTITY>.class, cascade=CascadeType.<CASCADE_TYPE>,
fetch = FetchType.<FETCH_TYPE>, mappedBy = "<MAPPED_BY>")
@OrderBy("<ORDER_BY>")
@JoinTable(name="<JOIN_TABLE_NAME>", joinColumns=@JoinColumn(name=
"<JOIN_COLUMN_NAME>", referencedColumnName="<JOIN_COLUMN_REFERENCED_COLUMN>"),
inverseJoinColumns=@JoinColumn(name="<INVERSE_JOIN_COLUMN_NAME>",
referencedColumnName="<INVERSE_JOIN_COLUMN_REFERENCED_COLUMN>"))

3.6.8 One-to-one mapping


Use a One-to-One Mapping to define a relationship with one-to-many multiplicity.
1. In the Persistence Outline view, select the field to map. The Persistence Properties
view (for attributes) displays the properties for the selected.
2. In the Map As field, select One-to-one.
3. Use this table to complete the remaining fields on the General tab in Persistence
Properties view.

3-18 Dali Object-Relational Mapping Tool User Guide


Mapping an entity

Property Description Default


Target Entity The entity to which this attribute is null
mapped.
You do not need to explicitly specify
the target entity, since it can be
inferred from the type of object
being referenced.
Cascade Type See "Cascade Type" on page 4-4 for Default
details.
■ Default
■ All
■ Persist
■ Merge
■ Remove
Fetch Type Defines how data is loaded from the Eager
database. See "Fetch Type" on
page 4-4 for details.
■ Eager
■ Lazy
Optional Specifies if this field is can be null. Yes
Mapped By The database field that owns the
relationship.

4. Use this table to complete the fields on the Join Columns tab tab in the Persistence
Properties view.

Property Description Default


Join Column Specify a mapped column for joining By default, the mapping is assumed
an entity association. This field to have a single join.
corresponds to the @JoinColum
attribute.
Select Override Default, then Add,
Edit, or Remove the join columns.

Eclipse adds the following annotations to the field:


@OneToOne(targetEntity=<TARGET_ENTITY>, cascade=CascadeType.<CASCADE_TYPE>,
fetch = FetchType.<FETCH_TYPE>, mappedBy = "<MAPPED_BY>")
@JoinColumn(name="<JOIN_COLUMN_NAME>", referencedColumnName=
"<JOIN_COLUMN_REFERENCED_COLUMN>", insertable = <INSERTABLE>,
updatable = <UPDATABLE>)

3.6.9 Transient mapping


Use the Transient Mapping to specify a or field of the entity class that is not persistent.
To create a version mapping:
1. In the Persistence Outline view, select the field to map. The Persistence Properties
view (for attributes) displays the properties for the selected.
2. In the Map As field, select Transient.

Tasks 3-19
Generating entities from tables

Eclipse adds the following annotation to the field:


@Transient

3.6.10 Version mapping


Use a Version Mapping to specify the field used for optimistic locking. If the entity is
associated with multiple tables, you should use a version mapping only with the
primary table. You should have only a single version mapping per persistent entity.
Version mappings may be used only with the following attribute types:
■ int
■ Integer
■ short, Short
■ long, Long
■ Timestamp
To create a version mapping:
1. In the Persistence Outline view, select the field to map. The Persistence Properties
view (for attributes) displays the properties for the selected.
2. In the Map As field, select Version.
3. Use this table to complete the remaining fields on the Persistence Properties view.

Property Description Default


Column The database column (and its table) By default, the Column is assumed
mapped to the entity attribute. See to be named identically to the
"Column" on page 4-3 for details. attribute and always included in
the INSERT and UPDATE
■ Name – Name of the database
statements.
column.
■ Table – Name of the database
table. This must be the primary
table associated with the
attribute’s entity.
■ Insertable – Specify if the column
is always included in SQL
INSERT statements.
■ Updatable – Specify if the column
is always included in SQL
UPDATE statements.

Eclipse adds the following annotations to the field:


@Version
@Column(table="<COLUMN_TABLE>", name="<COLUMN_NAME>", insertable=false,
updatable=false)

3.7 Generating entities from tables


Use this procedure to generate Java persistent entities from database tables. You must
add persistence to your project and establish a database connection before generating

3-20 Dali Object-Relational Mapping Tool User Guide


Generating tables (DDL scripts) from entities

persistent entities. See "Adding persistence to a Java project" on page 3-1 for more
information.
1. Right-click the persistent project in the Package Explorer and select Java
Persistence > Generate Entities.

Figure 3–18 Generating Entities

2. On the Generate Entities from Tables dialog dialog, select the tables from which to
generate Java persistent entities and click Finish.
Eclipse creates a Java persistent entity for each database table. Each entity contains
fields based on the table’s columns. Eclipse will also generate entity relationships
(such as one-to-one) based on the table constraints. Figure 3–19 illustrates how Eclipse
generates entities from tables.

Figure 3–19 Generating Entities from Tables

3.8 Generating tables (DDL scripts) from entities


Use this procedure to generate DDL script (for database tables) from your persistent
entities. You must establish a database connection before generating DDL files.
1. Right-click the persistent project in the Package Explorer and select Java
Persistence > Generate DDL.

Tasks 3-21
Validating mappings and reporting problems

Figure 3–20 Generating DDL from Entities

2. Complete the information on each page of the Generate Database DDL from
Entities wizard.
Refer to the "Using web tools" section of the Web Application Development Guide
for additional information.

3.9 Validating mappings and reporting problems


Errors and warnings on persistent entities and mappings are indicated with a red error
or yellow warning next to the resource with the error, as well as the parent containers
up to the project.

Figure 3–21 Sample Errors and Warnings

This section contains information on the following:


■ Error messages

3.9.1 Error messages


This section contains information on error messages (including how to resolve the
issue) you may encounter while working with Dali.

3-22 Dali Object-Relational Mapping Tool User Guide


Validating mappings and reporting problems

Column "<COLUMN_NAME>" cannot be resolved.


You mapped an entity’s field to an incorrect or invalid column in the database table.
By default, Dali will attempt to map each field in the entity with an identically named
row in the database table. If the field’s name differs from the row’s name, you must
explicitly create the mapping.
Map the field to a valid row in the database table as shown in "Mapping an entity" on
page 3-10.

Entity does not have an Id.


You created a persistent entity without identifying its primary key. A persistent entity
must have a primary key field designated with an @Id annotation.
Add an ID mapping to the entity as shown in "ID mapping" on page 3-13.

MappedBy specified on both sides of the "<MAPPED_FIELD>" relationship.


You selected a Mapped By database field on both the source and target of a
Many-to-many mapping. This field is required only on the non-owning side of the
relationship.
See "Persistence Properties view (for attributes)" on page 4-3 for more information.

MappedBy specified on "<MAPPED_FIELD>" is not a valid mapping type.


You selected in invalid database field as the owner of a One-to-one mapping. On the
General tab of the mapping, select the field in the database table that "owns" the
relationship. This field is required only on the non-owning side of the relationship
See "Persistence Properties view (for attributes)" on page 4-3 for more information.

Multiple Version properties are not allowed.


You created two version mappings for an entity. Each persistent entity may have a
single Version mapping. Change the mapping type of one of the fields to a different
mapping type.
See "Mapping an entity" on page 3-10 for more information.

Table "<TABLE_NAME>" cannot be found on the database.


You associated a persistent entity to an incorrect or invalid database table. By default,
Dali will attempt to associate each persistent entity with an identically named
database table. If the entity’s name differs from the table’s name, you must explicitly
create the association.
Associate the entity with a valid database table as shown in "Adding persistence to a
class" on page 3-5.

Target "<CLASS_NAME>" class is not an entity.


You created an relationship mapping from a field in an entity to a nonpersistent class.
The target of OR relationship must be an entity.
Map the target class as an entity as shown in "Persistent entity" on page 3-5. See
"Mapping an entity" on page 3-10 for more information.

The join column "<COLUMN_NAME>" cannot be found on the table.


The column that you selected to join a relationship mapping does not exist on the
database table. Either select a different column on the Join Table tab or create the
necessary column on the database table.

Tasks 3-23
Modifying persistent project properties

See "Persistence Properties view (for attributes)" on page 4-3 for more information.

The referenced column "<COLUMN_NAME>" cannot be found on the table.


The column that you selected to join a relationship mapping does not exist on the
database table. Either select a different column on the Join Table tab or create the
necessary column on the database table.
See "Persistence Properties view (for attributes)" on page 4-3 for more information.

The table "<TABLE_NAME>" cannot be found on the database.


You attempted to associate an entity or mapping to a table that does not exist on the
database. Verify that you are connected to the database and create the specific table, if
necessary.
See "Project Properties page – Persistence Options" on page 4-7 for more information.

The table "<TABLE_NAME>" is not associated with the owning entity.


The column that you selected to join a relationship mapping is not associated with the
referenced (owning) entity. You must associate each entity with a database table on
the entity’s General tab in the Persistence Properties view.
See "Persistence Properties view (for entities)" on page 4-3 for more information.

Version mapping type must be int, Integer, short, Short, long, Long, or
Timestamp.
For a Version mapping, the attribute must be mapped to a database column of one of a
valid type, as listed in "Version mapping" on page 3-20. See "Mapping an entity" on
page 3-10 for more information.

Version mappings must be mapped to the primary table.


For a Version mapping, the attribute must be mapped to the primary table associated
with the entity. Confirm that the Column Name field of the version mapping is
identical to the Table field on the entity’s General tab. See "Version mapping" on
page 3-20 and "Mapping an entity" on page 3-10 for more information.

3.10 Modifying persistent project properties


Each persistent project must be associated with a database connection. To create a new
database connection, click Database Connection use the New Connection wizard.
Use this procedure to modify the database associated with your persistent project.
1. Right-click the project in the Explorer view and select Properties. The Properties
page appears.

3-24 Dali Object-Relational Mapping Tool User Guide


Modifying persistent project properties

Figure 3–22 Properties – Persistence Page

2. Use this table to complete the remaining fields on the Properties – Java Persistence
page and click OK.

Property Description
Database Connection Database connection to use to store the persistent entities. To
reconnect to the selected connection, click Reconnect.
Database Schema Schema of the Database Connection to use.
Note: You must be connected to the database before selecting
the schema.

To create a new connection, click Add connections.

Tasks 3-25
Modifying persistent project properties

3-26 Dali Object-Relational Mapping Tool User Guide


4
Reference

This section includes detailed help information for each of the following elements in
the Dali OR Mapping Tool:
■ Wizards
■ Property pages
■ Preferences
■ Dialogs
■ Persistence perspective
■ Icons and buttons
■ Dali Developer Documentation

4.1 Wizards
This section includes information on the following wizards:
■ Generate Database DDL from Entities wizard

4.1.1 Generate Database DDL from Entities wizard


Use the Generate DDL wizard to generate DDL files from your Java persistence
entities. You must have a defined database connection (and be connected) before using
this wizard.
The wizard contains the following pages:
■ Options page
■ Objects page
■ Save and Run DDL page
■ Summary page
Refer to the "Using data tools" section of the Web Application Development Guide for
additional information.

4.2 Property pages


This section includes information on the following property pages:

Reference 4-1
Property pages

■ Persistence Properties view (for entities)


■ Persistence Properties view (for attributes)
■ Persistence Outline view

4.2.1 Persistence Properties view (for entities)


The Persistence Properties view displays the persistence information for the currently
selected entity and contains the following tabs:
■ General tab
■ Inheritance tab

4.2.1.1 General tab


This table lists the fields available on the General tab in the Persistence Properties view
for each entity type.

Property Description Default Available for Entity Type


Access Type Specify how the entity its access instance Property Persistent entity,
variables. Embeddable, and
Mapped superclass
■ Property – Persistent state accessed
through the property accessor methods.
The property accessor methods must be
public or private.
■ Field – Instance variables are accessed
directly. All non-transient instance
variables are persistent.
Note: This field is for display only, based on
the properties in the orm.xml: If only the
methods of the class are annotated, property
access type is used. In all other cases, field
access type is used.
Name The name of this entity. By default, the class Persistent entity
name is used as the entity name.
Table Name The primary database table associated with the Persistent entity
entity.
Attribute Specify a property or field to be overridden Persistent entity
Overrides (from the default mappings).
Column The database column (from the Table Name) Persistent entity
mapped to the entity.
Name Name of the database column. Persistent entity
Table Name of the database table that contains the Persistent entity
selected column.
Insertable Specifies if the column is always included in True Persistent entity
SQL INSERT statements.
Updatable Specifies if this column is always included in True Persistent entity
SQL UPDATE statements.

4.2.1.2 Inheritance tab


This table lists the fields available on the Inheritance tab in the Persistence Properties
view for each entity type.

4-2 Dali Object-Relational Mapping Tool User Guide


Property pages

Property Description Default


Strategy Specify the strategy to use when mapping a Single table
class or class hierarchy:
■ Single table – All classes in the hierarchy
are mapped to a single table.
■ Joined – The root of the hierarchy is
mapped to a single table; each child maps
to its own table.
■ Table per class – Each class is mapped to a
separate table.
Discriminator Use to specify the name of the discriminator
Column column when using a Single or Joined
inheritance strategy.
Discriminator Type se this field to set the discriminator type to
Char or Integer (instead of its default:
String). The Discriminator Value must
conform to this type.
Discriminator Value Specify the discriminator value used to
differentiate an entity in this inheritance
hierarchy. The value must conform to the
specified Discriminator Type.

Refer to "Specifying entity inheritance" on page 3-9 for additional information.

4.2.2 Persistence Properties view (for attributes)


The Persistence Properties view displays the persistence information for the currently
selected mapped attribute and contains the following tabs:
■ General tab
■ Join Table tab
■ Join Columns tab
■ PK Generation tab
See "Mapping an entity" on page 3-10 for more information.

4.2.2.1 General tab


This table lists the properties available on the General tab in the Persistence Properties
view for each mapping type.

Available for
Property Description Default Mapping Type
Map As Define the mapping type for the Basic All mapping types
attribute
Column The database column that By default, the Column is Basic mapping,
contains the value for the assumed to be named Embedded mapping,
attribute. This property identically to the attribute. ID mapping, Version
corresponds to the @Column mapping
annotation.

Reference 4-3
Property pages

Available for
Property Description Default Mapping Type
Name Name of the database column. Basic mapping,
Embedded mapping,
ID mapping
Table Name of the database table that Basic mapping,
contains the selected column. Embedded mapping,
ID mapping
Insertable Specifies if the column is always True Basic mapping,
included in SQL INSERT Embedded mapping,
statements. ID mapping
Updatable Specifies if this column is always True Basic mapping,
included in SQL UPDATE Embedded mapping,
statements. ID mapping
Fetch Type Defines how data is loaded from Eager Basic mapping,
the database: One-to-one mapping
■ Eager – Data is loaded in
before it is actually needed.
■ Lazy – Data is loaded only
when required by the
transaction.
Optional Specifies if this field is can be Yes Basic mapping,
null. One-to-one mapping
Temporal Specifies if this field is one of the Basic mapping, ID
following: mapping
■ Date – java.sql.Date
■ Time – java.sql.Time
■ Timestamp –
java.sql.Timestamp
This field corresponds to the
@Temporal annotation.
Target Entity The persistent entity to which the One-to-one mapping
attribute is mapped.
Cascade Type Specify which operations are One-to-one mapping
propagated throughout the entity.
■ All – All operations
■ Persist
■ Merge
■ Move
Mapped By The field in the database table One-to-one mapping
that "owns" the relationship. This
field is required only on the
non-owning side of the
relationship.
Order By Specify the default order for Primary key One-to-many
objects returned from a query: mapping.
Many-to-many
■ Primary key
mapping,
This field corresponds to the Many-to-one mapping
@OrderBy annotation.

4-4 Dali Object-Relational Mapping Tool User Guide


Property pages

Available for
Property Description Default Mapping Type
Attribute Overrides Overrides the column mappings Embedded mapping
from the mapped, entity tabled.
Embedded mapping
(for example, if the inherited
column name is incompatible
with a pre-existing data model, or
invalid as a column name in your
database).

4.2.2.2 Join Table tab


Use this tab to specify a mapped column for joining an entity association. By default,
the mapping is assumed to have a single join.
This table lists the fields available on the Join Table tab in Properties view for
One-to-many mapping and Many-to-many mapping mapping types.

Property Description Default


Name Name of the join table that contains By default, the name is
the foreign key column. assumed to be the primary
tables associated with the
entities concatenated with an
underscore.
Join Columns Specify a mapped column for By default, the mapping is
joining an entity association. This assumed to have a single join.
field corresponds to the
@JoinColum attribute.
Select Override Default, then Add,
Edit, or Remove the join columns.
Inverse Join Columns Select Override Default, then Add,
Edit, or Remove the join columns.

4.2.2.3 Join Columns tab


This table lists the fields available on the Join Table tab in Properties view for
Many-to-one mapping and One-to-one mapping mapping types.

Property Description Default


Join Column Specify a mapped column for By default, the mapping is
joining an entity association. This assumed to have a single join.
field corresponds to the
@JoinColum attribute.
Select Override Default, then Add,
Edit, or Remove the join columns.

4.2.2.4 PK Generation tab


This table lists the fields available on the PK Generation tab in Properties view for ID
mapping types.

Reference 4-5
Property pages

Property Description Default


Primary Key These fields define how the Generated Value
Generation primary key is generated. These
fields correspond to the
@GeneratedValue annotation.
Strategy ■ Auto Auto
■ Sequence – Values are assigned
by a sequence table (see
Sequence Generator).
■ Identity – Values are assigned
by the database’s Identity
column.
■ Table – Values are assigned by
a database table (see Table
Generator).
Generator Name Unique name of the generated
value.
Table Generator These fields define the database
table used for generating the
primary key and correspond to the
@TableGenerator annotation.
These fields apply only when
Strategy = Table.
Name Unique name of the generator.
Table Database table that stores the
generated ID values.
Primary Key Column The column in the table generator’s
Table that contains the primary
key.
Value Column The column that stores the
generated ID values.
Primary Key Column The value for the Primary Key
Value Column in the generator table.
Sequence Generator These fields define the database
table used for generating the
primary key and correspond to the
@SequenceGenerator
annotation. These fields apply only
when Strategy = Sequence.
Name Name of the sequence table to use
for defining primary key values.
Sequence Unique name of the sequence.

4.2.3 Persistence Outline view


The Persistence Outline view displays an outline of the structure (its attributes and
mappings) of the entity that is currently selected or opened in the editor. The
structural elements shown in the outline are the entity and its fields.

4-6 Dali Object-Relational Mapping Tool User Guide


Dialogs

Figure 4–1 Sample Persistence Outline View

4.3 Preferences
This section includes information on the following preference pages:
■ Project Properties page – Persistence Options

4.3.1 Project Properties page – Persistence Options


Use the Persistence options on the Properties page to select the database connection to
use with the project.
This table lists the properties available in the Persistence Properties page.

Property Description
Database Connection The database connection used to map the persistent entities.
■ To create a new connection, click Add Connections.
■ To reconnect to an existing connection, click Reconnect.
Database Schema The database schema used to map the persistent entities. You
must be selected to the database before selecting a schema.

See "Modifying persistent project properties" on page 3-24 for additional information.

4.4 Dialogs
This section includes information on the following preference pages:
■ Add Persistence dialog
■ Generate Entities from Tables dialog

4.4.1 Add Persistence dialog


Use the Add Persistence dialog to define the database connection used to store the
persistence entities and to create the persistence.xml file.
This table lists the properties available in the Add Persistence dialog.

Reference 4-7
Dialogs

Property Description
Database Settings Use these fields to define the database connection used to store
the persistent entities.
Connection The database connection used to map the persistent entities.
Schema The database schema used to map the persistent entities. You
must be selected to the database before selecting a schema.
Classpath Configuration Add libraries or JARs that contain the Java Persistence API
(JPA) and entities to the project’s Java Build Path.
Packaging Settings Use these fields to create the persistence.xml file.
Create persistence.xml Specify if Dali should create the persistence.xml file.
Persistence Version Select the version of the persistence provider.
Persistence Provider The name of the JPA provider’s
javax.persistence.spi.PersistenceProvider class.
Persistence Unit Name The name used to identify the persistence unit. You can use this
name when referencing the persistence unit by the
PersistenceContext and PersistenceUnit annotations
or when creating an entity manager factor programmatically.

See "Adding persistence to a Java project" on page 3-1 for more information.

4.4.2 Generate Entities from Tables dialog


Use the Generate Entities dialog to create Java persistent entities from your database
tables and columns.
This table lists the properties available in the Generate Entities dialog.

Property Description
Source Folder Enter a project folder name in which to generate the Java
persistent entities, or click Browse to select an existing folder.
Package Enter a package name in which to generate the Java persistent
entities, or click Browse to select an existing package.
Tables Select the tables from which to create Java persistent entities.
The tables shown are determined by the database connection
that you defined in the Project Properties page – Persistence
Options.

See "Generating entities from tables" on page 3-20 for more information.

4.4.3 Edit Join Columns Dialog


Use the Join Columns dialog to create or modify the join tables and columns in
relationship mappings.
This table lists the properties available in the Join Columns dialog.

4-8 Dali Object-Relational Mapping Tool User Guide


Icons and buttons

Property Description
Name Name of the joint table column that contains the foreign key
column.
Referenced Column Name Name of the database column that contains the foreign key
reference for the entity relationship.

4.5 Persistence perspective


The Persistence perspective defines the initial set and layout of views in the
Workbench window when using Dali. By default, the Persistence perspective includes
the following vies:
■ Persistence Outline view
■ Persistence Properties view (for entities)

Figure 4–2 Sample Persistence Perspective

4.6 Icons and buttons


This section includes information on each of the icons and buttons used in the Dali OR
Mapping Tool.
■ Icons

Reference 4-9
Icons and buttons

■ Buttons

4.6.1 Icons
The following icons are used throughout the Dali OR Mapping Tool.

Icon Description
Nonpersistent class

Persistent entity

Embeddable entity

Mapped superclass

Basic mapping

Embedded mapping

Embedded ID mapping

ID mapping

Many-to-many mapping

Many-to-one mapping

One-to-many mapping

One-to-one mapping

Transient mapping

Version mapping

4.6.2 Buttons
The following buttons are used throughout the Dali OR Mapping Tool.

4-10 Dali Object-Relational Mapping Tool User Guide


Dali Developer Documentation

Icon Description
Persistence perspective

4.7 Dali Developer Documentation


Additional Dali documentation is available online at:
http://wiki.eclipse.org/index.php/Dali_Developer_Documentation
This developer documentation includes information about:
■ Dali architecture
■ Plugins that comprise the Dali JPA Eclipse feature
■ Extension points

Reference 4-11
Dali Developer Documentation

4-12 Dali Object-Relational Mapping Tool User Guide


5
Tips and tricks

The following tips and tricks give some helpful ideas for increasing your productivity.
■ Database Connections
■ Schema-based persistence.xml

Tip Description
Database Connections When starting a new workbench session, be sure to reconnect to
your database (if you are working online). This allows Dali to
provide database-related mapping assistance and validation.
Schema-based If you are behind a firewall, you may need to configure your Eclipse
persistence.xml workspace proxy in the Preferences dialog (Preferences > Internet >
Proxy Settings) to properly validate a schema-based
persistence.xml file.

Tips and tricks 5-1


5-2 Dali Object-Relational Mapping Tool User Guide
6
What’s new

This section contains descriptions of the following new feature and significant changes
made to the Dali OR Mapping Tool for Release 0.5.0:
■ Generate Persistent Entities from Tables wizard
■ Generate DDL from Entities wizard
■ Create and Manage the persistence.xml file

6.1 Generate Persistent Entities from Tables wizard


Use the Generate Entities from Tables wizard to quickly create Java persistent entities
from your database tables.

Figure 6–1 Generating Entities

Dali automatically creates the necessary OR mappings, based on your database table
constraints.

6.2 Generate DDL from Entities wizard


Use the Generate DDL wizard to quickly create DDL scripts from your persistent
entities.

What’s new 6-1


Create and Manage the persistence.xml file

Figure 6–2 Generating DDL

Dali automatically creates the necessary primary and foreign keys, based on your
entity mappings.

6.3 Create and Manage the persistence.xml file


When adding persistence to a Java project, you can also create the
perssistence.xml file.

6-2 Dali Object-Relational Mapping Tool User Guide


Create and Manage the persistence.xml file

Figure 6–3 Add Java Persistence Dialog

Use the Packaging Settings options to create the persistence.xml file. After adding
your persistent classes, use the Java Persistence > Synchronize Classes option to add
the classes to the persistence.xml file.

Figure 6–4 Synchronizing the persistence.xml File.

What’s new 6-3


Create and Manage the persistence.xml file

6-4 Dali Object-Relational Mapping Tool User Guide


7
Legal

The material in this guide is copyright © 2006, by Oracle.

7.1 About this content


Terms and conditions regarding the use of this guide.
May 2, 2006

License
The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless
otherwise indicated below, the Content is provided to you under the terms and
conditions of the Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is
available at http://www.eclipse.org/legal/epl-v10.html. For purposes of
the EPL, "Program" will mean the Content.
If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party ("Redistributor") and different terms and
conditions may apply to your use of any object code in the Content. Check the
Redistributor’s license that was provided with the Content. If no such license exists,
contact the Redistributor. Unless otherwise indicated below, the terms and conditions
of the EPL still apply to any source code in the Content and such source code may be
obtained at http://www.eclipse.org.

Legal 7-1
About this content

7-2 Dali Object-Relational Mapping Tool User Guide


Index

Annotations synchronizing, 3-5


classpath configuration, persistence, 4-8
@Basic, 3-11
columns
@Column, 4-3
discriminator, 3-9
@DiscriminatorColumn, 3-9
join, 3-17, 3-19, 4-5
@DiscriminatorValue, 3-10
mapping to, 4-3
@Embeddable, 3-6
value, 3-10
@Embedded, 3-12
connections, database, 3-2
@EmbeddedId, 3-13
@Entity, 3-5
@GeneratedValue, 4-6 D
@Id, 3-13 database tables
@Inheritance, 3-9 generating entities from, 3-21
@JoinColumn, 3-17, 3-19, 4-5 generating from entities, 3-21
@ManyToMany, 3-15 database, persistence
@ManyToOne, 3-16 connection, 3-2, 4-7, 4-8
@MappedSuperclass, 3-7 schema, 4-7, 4-8
@OneToMany, 3-17 developer documentation, 4-11
@OneToOne, 3-18
@SequenceGenerator, 4-6
@Transient, 3-19 E
@Version, 3-20 eager fetch, 4-4
EJB. see persistent entities
A embeddable class
@Embeddable, 3-6
Add Persistence dialog, 3-2, 3-3, 4-1, 4-7 about, 3-6
adding persistence to projects, 3-1 embedded ID mapping
@OrderBy, 4-4 @EmbeddedId, 3-13
@Temporal, 4-4 about, 3-13
annotations. See specific annotation. embedded mapping
architecture of Dali feature, 4-11 @Embedded, 3-12
attributes about, 3-12
mapping, 2-1 entities
Persistence Properties view, 4-3 @Entity annotation, 3-5
about, 2-1
B creating tables from, 3-21
embeddable, 3-6
basic mapping
from tables, 3-20, 4-8
@Basic, 3-11
mapped superclass, 3-7
about, 3-11
mapping, 1-6
persistence, 1-4
C Persistence Properties view, 4-2
persistent, 3-5
classes
error messages, Dali, 3-22
adding persistence to, 3-5
extension points, Dali feature, 4-11
embeddable, 3-6
entity, 3-5

Index-1
F classes, 3-5
fields. See transient
fetch type, 4-4

O
G
one-to-many mapping
Generate Entities from Tables dialog, 3-21, 4-8
@OneToMany, 3-17
generated values
about, 3-17
ID mappings, 4-6
one-to-one mapping
sequence, 4-6
@OneToOne, 3-18
about, 3-18
I OR (object-relational) mappings. See mappings
ordering, 4-4
ID mapping
outline, persistence, 4-6
@Id, 3-13
about, 3-13
inheritance P
entity, 3-9, 4-2 persistence
joined tables, 3-10 about, 2-1
single table, 3-10 adding to projects, 3-1
Inheritance tab, 4-2 database connection, 4-7, 4-8
installation, Dali, 1-1 database schema, 4-7, 4-8
entity class, 3-5
J options, 4-7
projects, 4-1, 4-7
Java Persistence API (JPA), adding to project, 3-2
Persistence Outline view, 4-6
joined tables, inheritance, 3-10
Persistence perspective, 4-9
Persistence Properties view
L attributes, 4-3
lazy fetch, 4-4 entities, 4-2
Persistence XML Editor, 3-4
persistence.xml file
M about, 2-2
many-to-many mapping creating, 3-2
@ManyToMany, 3-15 editor, 3-4
about, 3-15 managing, 3-2
many-to-one mapping sample, 3-3
@ManyToOne, 3-16 synchronizing with classes, 3-5
about, 3-16 persistent entity, 3-5
mapped superclass perspective, persistence, 4-9
@MappedSuperclass, 3-7 problems, 3-22
about, 3-7 projects
mapping entities, 1-6 creating new, 1-2
mappings options, 4-7
about, 2-1 persistence, 4-1, 4-7
basic, 3-11 persistence, adding, 3-1
embedded, 3-12
embedded ID, 3-13 Q
ID, 3-13
many-to-many, 3-15 quick start, 1-1
many-to-one, 3-16
one-to-many, 3-17 R
one-to-one, 3-18
requirements
problems, 3-22
persistent entities, 3-5
transient, 3-19
requirements, Dali, 1-1
version, 3-20

N S
schema, database, 4-7, 4-8
nonpersistent
single table inheritance, 3-10

Index-2
superclass, 3-7

T
tables
creating entities from, 3-20, 4-8
from entities, 3-21
inheritance, 3-10
temporal, 4-4
transient mapping
@Transient, 3-19
about, 3-19
tutorial, Dali, 1-8

V
version mapping
@Version, 3-20
about, 3-20
views
Persistence Outline view, 4-6
Persistence Properties view, 4-2, 4-3

W
warning messages, Dali, 3-22

Index-3
Index-4

You might also like