Choosing the primary key ID Generator
From Wiki
|
Modeling the data model requires also to configure an ID Generator for each primary key attribute. This property is used by Hibernate to compute the primary key value when a new entity instance is persitently saved into the database. To configure the ID Generator you have to set the ID Generator property in the Mapping tab of the Properties View of the selected key attribute, and choose one of the available ID Generator.
The available ID Generator are:
- increment. It generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. Do not use in multithread environments like a cluster architecture. In this case the input coupling of the Create Unit also shows one input parameter for the key attribute of the master entity. You can provide the primary key value to use. If the provided value is already present in the database, Hibernate automatically increments it to the first available one.
- identity. It supports identity columns in DB2, MySQL, MS SQL Server. The returned identifier is of type long, short or int.
- sequence. It uses a sequence in DB2, PostgreSQL, Oracle. The returned identifier is of type long, short or int. In this case you have also to specify the sequence you want to use, choosing one of the available options in the Sequence Name property in the Properties View. The available sequences are those previously defined in your database. This kind of generator is available only if, after a refresh on the database, at least one sequence is found.
- uuid. It uses a 128-bit UUID algorithm to generate identifiers of type string, unique within a network (the IP address is used). The UUID is encoded as a string of hexadecimal digits of length 32. This ID Generator is available only for string key attributes.
- assigned. It lets the application to assign an identifier to the object before save() is called. In this case the input coupling of the Create Unit also shows one input parameter for each key attribute of the master entity. In this way you can provide the primary key value to use and it is your job to be sure that the primary key is unique. This ID Generator is the default one in case of composite primary key or in case of not integer key attribute.
