Dali Java Persistence Tools User Guide Release 3.2 Release 3.2 |
|
Creating queries |
Generating entities from tables |
Home > User Guide > Tasks > 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
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:
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.
Complete each field in the Basic Mapping area.
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
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:
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.
Complete each field in the Element Collection Mapping area.
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
Use an Embedded Mapping to specify a persistent field or property of an entity whose value is an instance of an embeddable class.
In the JPA Structure view, right-click the field to map.
Select Map as > Embedded. The JPA Details view (for attributes) displays the properties for the selected field.
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
Use an Embedded ID Mapping to specify the primary key of an embedded ID. These mappings may be used with a Embeddable entities.
In the JPA Structure view, select the field to map.
Right-click the field and then select Map As > Embedded Id. The JPA Details view (for attributes) displays the properties for the selected field.
Complete each field in the Embedded ID Mapping area.
Eclipse adds the following annotations to the field:
@EmbeddedId
Related tasks
Related references
Related concepts
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.
In the JPA Structure view, select the field to map.
Right click the filed and then select Map as > ID. The JPA Details view (for attributes) displays the properties for the selected.
Complete each field in the ID Mapping area.
Use the Primary Key Generation area to specify the strategy to use for generating primary keys.
Complete each field in the Primary Key Generation information area.
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
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.
In the JPA Structure view, select the field to map.
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.
Complete each field in the Many-to-Many Mapping area.
Use the Joining Strategy area to specify the join strategy (or table) for the mapping.
Complete each field in the Joining Strategy area.
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
Use a Many-to-One mapping to defines a single-valued association to another entity class that has many-to-one multiplicity.
In the JPA Structure view, select the field to map.
Right click the field and then select Map As > Many-to-One. The JPA Details view (for attributes) displays the properties for the selected.
Complete each field in the Many-to-Many Mapping area.
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
Use a One-to-Many Mapping to define a relationship with one-to-many multiplicity.
In the JPA Structure view, select the field to map.
Right-click the field and then select Map As > One-to-many. The JPA Details view (for attributes) displays the properties for the selected.
Complete each field in the One-to-Many Mapping area.
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
Use a One-to-One Mapping to define a relationship with one-to-many multiplicity.
In the JPA Structure view, select the field to map.
Right-click the field and then select Map As > One-to-One. The JPA Details view (for attributes) displays the properties for the selected.
Complete each field in the One-to-One Mapping area.
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
Use the Transient Mapping to specify a field of the entity class that is not persistent.
To create a transient mapping:
In the JPA Structure view, select the field to map.
Right-click the field and then select Map As Transient. The JPA Details view (for attributes) displays the properties for the selected.
There are no additional options for Transient mappings. Eclipse adds the following annotation to the field:
@Transient
Related tasks
Related references
Related concepts
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:
In the JPA Structure view, select the field to map.
Right-click the field and then select Map As > Version. The JPA Details view (for attributes) displays the properties for the selected.
Complete each field in the Version Mapping area.
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