This article describes the generator properties of HBM in Hibernate. The < generator> child element that must be declared in *.hbm.xml is the name of a Java class used to generate a unique identity for an instance of the persisted class.
The < generator> child element that must be declared in *.hbm.xml is the name of a Java class used to generate a unique identity for an instance of the persisted class.
< generator class= "sequence"/>
This is a very simple interface, and some applications can choose to provide their own specific implementations. Of course, Hibernate offers a lot of built-in implementations. Here are the quick names for some of the built-in generators:
Increment (incremental)
Used to generate a unique identifier for a long, short, or int type. Use only if no other process inserts data into the same table. Do not use under the cluster.
Identity
Provides support for db2,mysql, MS SQL Server, Sybase, and Hypersonicsql built-in identification fields. The identifier returned is a long, short, or int type.
Sequence (sequence)
Use a sequence (sequence) in Db2,postgresql, Oracle, SAP DB, Mckoi, and use a generator (generator) in InterBase. The identifier returned is a long, short, or int type.
Hilo (High and low position)
Use a high/low algorithm to efficiently generate long, short, or int type identifiers. Given a table and fields (the default is Hibernate_unique_key and Next_hi) as a high source of merit. The high/low algorithm generates identifiers that are unique only in a particular database. Do not use this builder in a connection obtained by using JTA or a user-supplied connection.
Seqhilo (Use the high and low position of the sequence)
Use a high/low algorithm to efficiently generate long, short, or int type identifiers, given the name of a database sequence (sequence).
Uuid.hex
Generates an identifier of the string type with a 128-bit UUID algorithm. Unique on a network (using an IP address). The UUID is encoded as a string of 32-bit 16-digit digits.
Uuid.string
Use the same UUID algorithm. The UUID is encoded as a string consisting of any ASCII character of 16 characters long. cannot be used in the PostgreSQL database
Native (local)
Select one of the identity, sequence or Hilo based on the capabilities of the underlying database.
Assigned (Program Settings)
Have the application assign an identifier to the object before save ().
Foreign (external reference)
Use an identifier for another associated object. Used in conjunction with the < one-to-one>.
<
className= "Onlyfun.caterpillar.User" table= "User"
>
<
IDName= "id" type= "string" unsaved-value= "null"
>
<
columnName= "user_id"
/>
<
GeneratorClass= "Uuid.hex"
/>
</id
>