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 queries
 
Next
Generating entities from tables
 

Mapping an entity

Dali supports the following mapping types for Java persistent entities:


Note:

Additional mapping types (such as Basic Collection mappings) may be available when using Dali with EclipseLink.


Related concepts

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 JPA Structure view, right-click the field to map. Select Map As > Basic. The JPA Details view (for attributes) displays the properties for the selected field.

    Figure 3-48 JPA Details, Basic mapping

    PA Details, Basic mapping
  2. Complete each field in the Basic Mapping area.

  3. Complete the remaining areas in the JPA Details view (for attributes).

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

Related tasks

Related references

Related concepts

Element collection mapping

Use an Element Collection to define a collection of Basic objects. The Basic values are stored in a separate collection table. Because the target is a Basic value (instead of an Entity), you can easily define collections of simple values without having to define a class for the value.

To create an element collection mapping:

  1. In the JPA Structure view, right-click the field to map. Select Map As > Element Collection. The JPA Details view (for attributes) displays the properties for the selected field.

    Figure 3-49 JPA Details, Element collection mapping

    PA Details, Element collection mapping
  2. Complete each field in the Element Collection Mapping area.

  3. Complete the remaining areas in the JPA Details view (for attributes).

Eclipse adds the following annotations to the field:

@ElementCollection
@CollectionTable(
        name="<TABLE_NAME>",
        joinColumns=@JoinColumn(name="<COLUMN_TABLE>")
)
@Column(name="<COLUMN_TABLE>")

Related tasks

Related references

Related concepts

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 JPA Structure view, right-click the field to map.

  2. Select Map as > Embedded. The JPA Details view (for attributes) displays the properties for the selected field.

    Figure 3-50 JPA Details, Embedded mapping

    PA Details, Element collection mapping
  3. Complete each field in the Embedded Mapping area.

Eclipse adds the following annotations to the field:

@Embedded
@AttributeOverride(
    column=@Column(
        table="<COLUMN_TABLE>", 
        name = "<COLUMN_NAME>"
    )
)

Related tasks

Related references

Related concepts

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 JPA Structure view, select the field to map.

  2. Right-click the field and then select Map As > Embedded Id. The JPA Details view (for attributes) displays the properties for the selected field.

    Figure 3-51 JPA Details, Embedded ID mapping

    PA Details, Element collection mapping
  3. Complete each field in the Embedded ID Mapping area.

Eclipse adds the following annotations to the field:

@EmbeddedId

Related tasks

Related references

Related concepts

ID mapping

Use an ID Mapping to specify the primary key of an entity. ID mappings may be used with a Entity or Mapped superclass. Each Entity must have an ID mapping.

  1. In the JPA Structure view, select the field to map.

  2. Right click the filed and then select Map as > ID. The JPA Details view (for attributes) displays the properties for the selected.

    Figure 3-52 JPA Details, ID mapping


  3. Complete each field in the ID Mapping area.

  4. Use the Primary Key Generation area to specify the strategy to use for generating primary keys.

    Figure 3-53 JPA Details, Primary key generation

    JPA Details, Primary key generation
  5. Complete each field in the Primary Key Generation information area.

  6. Complete the remaining areas in the JPA Details view (for attributes).

Additional fields will appear in the Primary Key Generation information area, depending on the selected Strategy. See "JPA Details view (for attributes)" for additional information.

Eclipse adds the following annotations to the field:

@Id
@Column(
    name="<COLUMN_NAME>", 
    table="<TABLE_NAME>", 
    insertable=<INSERTABLE>,
    updatable=<UPDATABLE>
)
@Temporal(<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>")

Related tasks

Related references

Related concepts

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 JPA Structure view, select the field to map.

  2. Right-click the field and then select Map As > Many-to-Many. The JPA Details view (for attributes) displays the properties for the selected field.

    Figure 3-54 JPA Details, Many to many mapping

    JPA Details, Primary key generation
  3. Complete each field in the Many-to-Many Mapping area.

  4. Use the Joining Strategy area to specify the join strategy (or table) for the mapping.

    Figure 3-55 JPA Details, Joining Strategy

    JPA Details, Joining Strategy
  5. Complete each field in the Joining Strategy area.

  6. Complete the remaining areas in the JPA Details view (for attributes).

Eclipse adds the following annotations to the field:

@JoinTable(
    joinColumns=@JoinColumn(name="<JOIN_COLUMN>"), 
    name = "<JOIN_TABLE_NAME>"
)
@ManyToMany(=Type.<_TYPE>, fetch=FetchType.<FETCH_TYPE>,
    targetEntity=<TARGET_ENTITY>, mappedBy = "<MAPPED_BY>")
@OrderBy("<ORDER_BY>")

Related tasks

Related references

Related concepts

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 JPA Structure view, select the field to map.

  2. Right click the field and then select Map As > Many-to-One. The JPA Details view (for attributes) displays the properties for the selected.

    Figure 3-56 JPA Details, Many-to-one mapping

    JPA Details, Many-to-one mapping
  3. Complete each field in the Many-to-Many Mapping area.

  4. Complete the remaining areas in the JPA Details view (for attributes).

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>, 
    =<_TYPE>
)

Related tasks

Related references

Related concepts

One-to-many mapping

Use a One-to-Many Mapping to define a relationship with one-to-many multiplicity.

  1. In the JPA Structure view, select the field to map.

  2. Right-click the field and then select Map As > One-to-many. The JPA Details view (for attributes) displays the properties for the selected.

    Figure 3-57 JPA Details, One-to-many Mapping

    JPA Details, One-to-many Mapping
  3. Complete each field in the One-to-Many Mapping area.

  4. Complete the remaining areas in the JPA Details view (for attributes):

Eclipse adds the following annotations to the field:

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


@OneToMany(targetEntity=<TARGET_ENTITY>.class, 
    =Type.<_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>"))

Related tasks

Related references

Related concepts

One-to-one mapping

Use a One-to-One Mapping to define a relationship with one-to-many multiplicity.

  1. In the JPA Structure view, select the field to map.

  2. Right-click the field and then select Map As > One-to-One. The JPA Details view (for attributes) displays the properties for the selected.

    Figure 3-58 JPA Details, One-to-one Mapping

    JPA Details, One-to-one Mapping
  3. Complete each field in the One-to-One Mapping area.

  4. Complete the remaining areas in the JPA Details view (for attributes):

Eclipse adds the following annotations to the field:

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

Related tasks

Related references

Related concepts

Transient mapping

Use the Transient Mapping to specify a field of the entity class that is not persistent.

To create a transient mapping:

  1. In the JPA Structure view, select the field to map.

  2. Right-click the field and then select Map As Transient. The JPA Details view (for attributes) displays the properties for the selected.

    Figure 3-59 JPA Details, Transient Mapping

    JPA Details, Transient Mapping

There are no additional options for Transient mappings. Eclipse adds the following annotation to the field:

@Transient

Related tasks

Related references

Related concepts

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 JPA Structure view, select the field to map.

  2. Right-click the field and then select Map As > Version. The JPA Details view (for attributes) displays the properties for the selected.

    Figure 3-60 JPA Details, Version Mapping

    JPA Details, Version Mapping
  3. Complete each field in the Version Mapping area.

  4. Complete the remaining areas in the JPA Details view (for attributes):

Eclipse adds the following annotations to the field:

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

Related tasks

Related references

Related concepts