Simple identifiers

An identifier is an attribute of a persistent class enabling this class to be identified in a unique way. In most cases, identifiers are mapped as SQL model primary keys.

image
An identifier belonging to a persistent class

To transform a persistent model attribute into an identifier, just check the "Identifier" tickbox.

You can define the following properties for an identifier in the SQL tab:

  • Persistent Name: Name of the SQL table to which the identifier will be mapped. If this field is left empty, Modelio will consider the name of the SQL field to be identical to that of the identifier.

  • Persistent Type: The SQL type of the identifier.

  • Generator: The name of the generator associated with this identifier.

Generators

A generator is used to generate unique identifiers for instances of persistent classes.

The "Generator" property on an identifier assigns a type of generator to the indentifier in question. Some generators require parameters. The "Parameters" property on an identifier is used to enter these parameters using the following syntax: paramname1, paramvalue1 ; paramname2, paramvalue2 ;…

  • native: Delegates identifier generation to the database.

  • increment: Generates identifiers of long, short or int type which are only unique if no other process inserts data into the same table. Should not be used in a clustered environment.

  • identity: Uses the DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL identity column. The returned identifier is of long, short or int type.

  • sequence: Uses sequences in DB2, PostgreSQL, Oracle, SAP DB, McKoi or a generator in Interbase. The returned identifier is of long, short or int type.

  • hilo: Uses a hi/lo algorithm to efficiently generate identifiers of long, short or int type, taking as "hi" value source a table and a column (by default, SQL_unique_key and next_hi respectively). The hi/lo algorithm only generates unique identifiers for a particular database.

  • seqhilo: Uses a hi/lo algorithm to efficiently generate identifiers of long, short or int type, given a base sequence name.

  • uuid: Uses a UUID 128 bits type algorithm to generate identifiers of string type, which are unique within the network (the IP address is used). The UUID is encoded in a string of 32 hexadecimal numbers. guid Uses a GUID string generated by the database for MS SQL Server and MySQL.

  • assigned: Lets the application assign an identifier to the object before the  save() method is called. This is the default strategy if no <generator> is specified.

  • select: Retrieves a primary key assigned by a trigger by selecting the line by any unique key.

  • foreign: Uses the identifier of an associated object. Normally used in conjunction with a <one-to-one> association on the primary key.

Composite identifiers

If a persistent class has more than one identifier, then we refer to composite identifiers. These compositie identifiers are mapped on composite primary keys in the SQL model.

The presence of a composite identifier results in a 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 the skeletons of these operations during Java generation. It will also add an implementation link to the Serializable interface where necessary.