Creating an identifier¶
An identifier is an attribute of a persistent class used to universally identify the persistent class in question. In most cases, this identifier will
be mapped as a Primary Key of the SQL model.
An identifier belonging to a persistent class
The following identifier properties can be defined in the Hibernate tab:
Name of the SQL field to which the identifier will be mapped. If this field remains empty, the name of the SQL field is considered to be identical to the name of the identifier.
The Hibernate type of the identifier.
The name of the generator associated with this identifier.
A generator is used to generate unique identifiers for the instances of persistent classes.
The “Generator” property of the identifier enables you to assign a generator type to the identifier. Certain generators require parameters. The
identifier’s “Parameters” property is used to enter these parameters, which must respect the following syntax: nameparam1, valueparam1 ; nameparam2, valueparam2 ; …
Delegates generation of identifiers to the database.
Generates long, short or int identifiers which are only unique if no other process inserts data into the same table.
Should not be used in a clustered environment.
Use of the DB2, MySQL, MS SQL Server, Sybase et HypersonicSQL identity column. The returned identifier is long, short or int.
Use of DB2, PostgreSQL, Oracle, SAP DB, McKoi or Interbase generator sequences. The returned identifier is long, short or int.
Uses a hi/lo algorithm to efficiently generate long, short or int identifiers, using a table and a column (by default, hibernate_unique_key and next_hi respectively) as the source of the “hi” value. The hi/algorithm only generates unique identifiers for a particular database.
Uses a hi/lo algorithm to efficiently generate long, short or int identifiers, given a sequence name as the basis.
Uses a UUID 128 bits type algorithm to generate string identifiers, unique within a network (the IP address is used). Le UUID is encoded in a string of 32 hexadecimal numbers.
Uses a GUID string generated by the databse for MS SQL Server and MySQL.
Lets the application affect an identifier to the object before the save() method is called. This is the default strategy if no <generator> has been specified.
Retrieves a primary key assigned by a trigger by selecting the line by a given unique key.
Uses the identifier of an associated object. Generally used in conjunction with a <one-to-one> association on the primary key.
We refer to composite identifiers where a persistent class contains more than one identifier. These composite identifiers are mapped on composite primary keys at SQL model level.
The presence of a composite identifier leads to a certain number of constraints: Your persistent classes must overload the equals() and hashCode() methods. They must also implement the Serializable interface.
If these methods are missing, the Hibernate Designer module will automatically create skeletons of these operations during Java generation. It will also add an implementation link to the Serializable interface where necessary.