Creating an association

Associations

Associations are used to manifest links between classes of the persistence model. The mapping rules applied to an association vary according to the cardinality of the association, its unidirectional or bidirectional aspect and on the type of SQL mapping chosen.

Modifying an association’s cardinality

An association has two roles, one at each extremity. The cardinality of an association depends on the cardinality of these two roles.

To modify the cardinality of a role:

  • Select the association and position yourself in the Hibernate tab.
  • Open the property page associated with the role that you want to modify.
  • Modify the cardinality of the role.

Relationship between the cardinality of roles and the cardinality of the association

Role 1 Role 2 Association
0..1 0..1 One To One
1..1 1..1 One To One | Not Null
0..1 0..* One To Many
1..1 1..* One To Many | Not Null
0..* 0..1 Many To One
1..* 1..1 Many To One | Not Null
0..* 0..* Many To Many
1..* 1..* Many To Many | Not Null

Making an association unidirectional or bidirectional

The navigability of an association depends on the navigability of its two roles.

To modify the navigability of a role:

  • Select the association and position yourself in the Hibernate tab.
  • Open the property page associated withe the role you want to change.
  • Modify the navigability of the role.

Defining the name of foreign keys

According to the type of mapping chosen for the association, the name of the foreign keys used at SQL model level must be configured.

To change the name of a foreign key:

  • Select the association and position yourself in the Hibernate tab.
  • Select the property page associated with the role that you want to modify.
  • You will then be able to use a Foreign-Key : identifiername property for each of the expected foreign keys.


Defining the name of a foreign key

Defining the name of the join table

If you choose to map an association to a join table at SQL model level, the name of the join table is defined in the following way:

  • If the “Persistent Name” property of the association is defined, the join table will be named after this property.
  • If this is not the case, the join table will be named from the name of the association.

Hibernate types supported

The Hibernate Designer module currently supports the following types for identifiers and properties:

  • Char
  • Float
  • Int
  • Byte
  • Short
  • Long
  • Double
  • java.lang.String
  • java.lang.Class
  • java.lang.Boolean
  • java.lang.Char
  • java.lang.Double
  • java.lang.Float
  • java.lang.Number
  • java.lang.Integer
  • java.lang.Long
  • java.lang.Character
  • java.sql.Clob
  • java.sql.Blob
  • java.util.TimeZone
  • java.util.Calendar
  • java.util.Currency
  • java.util.Date

The Hibernate Designer module currently supports the following types of collections (defined at association role level):

  • array –> []
  • bag –> java.util.Collection
  • bag –> java.util.List
  • list –> java.util.List
  • map –> java.util.Map
  • map –> java.util.SortedMap
  • set –> java.util.Set
  • set –> java.util.SortSet

Association mapping rules

Mapping Cardinality Navigability Type of mapping
One To One Unidirectional on Primary Key 1..1 Unidirectional Primary Key
One To One Unidirectional on Foreign Key 1..1 Unidirectional Foreign Key
One To One Unidirectional on Join Table 1..1 Unidirectional Join Table
One To One Bidirectional on Primary Key 1..1 Bidirectional Primary Key
One To One Bidirectional on Foreign Key 1..1 Bidirectional Foreign Key
One To One Bidirectional on Join Table 1..1 Bidirectional Join Table
One To Many Unidirectional on Foreign Key 1..* Unidirectional Foreign Key
One To Many Unidirectional on Join Table 1..* Unidirectional Join Table
Many To One Unidirectionnel on Foreign Key *..1 Unidirectional Foreign Key
Many To One Unidirectional on Join Table *..1 Unidirectional Join Table
Many To One Bidirectional on Foreign Key 1..* Bidirectional Foreign Key
Many To One Bidirectional on Join Table 1..* Bidirectional Join Table
Many To Many Unidirectional *..* Unidirectional Join Table
Many To Many Bidirectional *..* Bidirectional Join Table

Hibernate_Fig6_English.gif (20.8 KB) admin admin, 15 December 2015 09:45