Skip Headers
Dali Java Persistence Tools User Guide
Release 3.2
Release 3.2
  PDF
PDF
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Creating a JPA entity
 
Next
Adding virtual attributes
 

Adding persistence to a class

You can make a Java class into one of the following persistent types:

To add persistence to an existing Java class:

  1. Right-click the class in the Project Explorer and select JPA Tools > Make Persistent. The Make Persistent dialog appears.

    Figure 3-19 Make Persistence Dialog


  2. Complete the fields on the Make Persistent dialog, specify the persistence mapping for each class, and click Finish.

Dali adds the necessary annotation or entry in the XML mapping file for the class.

Related reference

Related concepts

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:

  1. Open the Java class in the Project Explorer.

  2. Select the class in the JPA Structure view.

  3. In the JPA Details view, click the mapping type hyperlink to access the Mapping Type Selection dialog. In the following figure, clicking entity invokes the dialog from the JPA Details View.

    Figure 3-20 The Mapping Type Hyperlink

    The JPA Details view for an entity showing the mapping type hyperlink.

    Tip:

    You can also change (or add) persistence for an entity by right-clicking the class in the JPA Structure View and then clicking Map As > Entity.


  4. Select Entity from the Mapping Type Selection dialog and then click OK.

    Figure 3-21 The Mapping Type Selection Dialog

    The Mapping Type selection dialog with Enity selected.
  5. Complete the remaining JPA Details view (for entities).

Related reference

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. Open the Java class in the Project Explorer.

  2. Select the class in the JPA Structure view.

  3. Click the mapping type hyperlink to open the Mapping Type Selection dialog.

  4. Select Embeddable and then click OK.

    Figure 3-22 Mapping Type Selection Dialog (Embeddable)

    The Mapping Type Selection dialog with Embeddable selected.
  5. Complete the remaining JPA Details view (for entities).

Related reference

Mapped superclass

An entity that extends a Mapped Superclass class inherits 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. Open the Java class in the Project Explorer.

  2. Select the class in the JPA Structure view.

  3. In the JPA Details view, click the mapping type hyperlink to open the Mapping Type Selection dialog.

  4. Select Mapped Superclass and then OK.

    Figure 3-23 Mapping Type Selection Dialog (Mapped Superclass)

    The Mapping Type Selection dialog with Mapped Superclass selected.
  5. Complete the remaining JPA Details view (for entities).

Related reference