Dali User Guide
Dali User Guide
User Guide
Release 0.5.0 for Eclipse
June 2006
Dali Object-Relational Mapping Tool User Guide
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
2. On the Select Perspective dialog, select Java Persistence and click OK. The
workbench adds the Persistence Outline and Persistence Properties views.
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.
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).
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.
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.
Now that you have created a project with persistence, you can continue with Creating
a Java persistent entity.
Eclipse adds the new entity to the project and adds the @Entity annotation to the
class.
Eclipse also displays the Address entity in the Persistence Outline view:
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.
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.
Eclipse updates the Address entity in the Persistence Outline view to show its 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.
3. Map each of the following fields (as Basic mappings) to the appropriate database
column:
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. 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.
7. Select Persistence and click OK. The Persistence Outline and Properties views
appear.
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;
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.
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.
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.
In the Persistence Outline, the id field is identified as the primary key by the following
icon:
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.
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
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)
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:
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.
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:
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.
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:
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
Concepts 2-1
Understanding JSR220: EJB 3.0
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
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.
■ 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.
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.
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>
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.
2. In the Persistence Properties view, use the Map As drop-list to select Entity.
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.
2. In the Persistence Properties view, use the Map As drop-list to select Embeddable.
Tasks 3-7
Creating a new Java persistent entity
2. In the Persistence Properties view, use the Map As drop-list to select Mapped
Superclass.
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. 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.
Tasks 3-9
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
Tasks 3-11
Mapping an entity
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
4. Use this table to complete the fields on PK Generation tab in the Persistence
Properties view.
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>",
valueColumnName = "<TABLE_GENERATOR_VALUE_COLUMN>",
pkColumnValue = "<TABLE_GENERATOR_PK_COLUMN_VALUE>")
@SequenceGenerator(name="<SEQUENCE_GENERATOR_NAME>",
sequenceName="<SEQUENCE_GENERATOR_SEQUENCE>")
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
4. Use this table to complete the fields on the Join Columns tab tab in the Persistence
Properties view.
Tasks 3-17
Mapping an entity
4. Use this table to complete the fields on the Join Table tab in the Persistence
Properties view.
@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>"))
4. Use this table to complete the fields on the Join Columns tab tab in the Persistence
Properties view.
Tasks 3-19
Generating entities from tables
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.
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.
Tasks 3-21
Validating mappings and reporting problems
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.
Tasks 3-23
Modifying persistent project properties
See "Persistence Properties view (for attributes)" 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.
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.
Tasks 3-25
Modifying persistent project properties
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
Reference 4-1
Property pages
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.
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).
Reference 4-5
Property pages
4.3 Preferences
This section includes information on the following preference pages:
■ Project Properties page – Persistence Options
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
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.
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.
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.
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.
Icon Description
Persistence perspective
Reference 4-11
Dali Developer Documentation
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.
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
Dali automatically creates the necessary OR mappings, based on your database table
constraints.
Dali automatically creates the necessary primary and foreign keys, based on your
entity mappings.
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.
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
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