The generator in hibernate is introduced in class =value

Source: Internet
Author: User
Tags db2 generator

The <generator> child element that must be declared in *.hbm.xml is the name of a Java class that is 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 provides a lot of built-in implementations. Here are some quick names for the built-in generators:
Increment (increment)
Used to generate a unique identity for a long, short, or int type. It can only be used if no other process is inserting data into the same table. Do not use under the cluster. (Supplemental: The primary key is incremented in numerical order, which is implemented by maintaining a variable in the current instance to hold the current maximum value, and then adding 1 as the primary key each time a primary key is generated, which can cause problems: if there are currently multiple instances accessing the same database, So because each instance maintains the primary key state, different instances can generate the same primary key, which causes the primary key to repeat the exception, so if there are multiple instance accesses to the same database, this method must be avoided. )
Identity
Provides support for built-in identity fields for Db2,mysql, MS SQL Server, Sybase, and Hypersonicsql. The returned identifiers are of type long, short, or int. (Supplemental: Use the primary key generation mechanism provided by the database, such as the self-increment primary key generation mechanism in SQL Server MySQL)
Sequence (sequence)
In Db2,postgresql, Oracle, SAP DB, Mckoi use sequences (sequence), and generators (generator) are used in InterBase. The returned identifiers are of type long, short, or int.
Hilo (High-low)
Use a high/low algorithm to efficiently generate identifiers for long, short, or int types. Given a table and a field (the default is Hibernate_unique_key and Next_hi respectively) as a high-level worthy source. The high/low algorithm generates identifiers that are unique only in a particular database. Do not use this generator for connections obtained using JTA or for connections provided by users themselves. (Supplemental: Requires an additional database table to save the primary key generation history state)
Seqhilo (using the high and low bits of the sequence)
Use a high/low algorithm to efficiently generate identifiers of long, short, or int types, given the name of a database sequence (sequence). (Supplemental: The Hilo algorithm implements the primary key generation mechanism, except that the primary key history state is saved in sequence, which is applicable to databases that support sequence, such as Oracle)
Uuid.hex
Generates an identifier for the string type with a 128-bit UUID algorithm. Unique in a network (IP address is used). The UUID is encoded as a string of 32-bit 16 decimal digits.
Uuid.string
Use the same UUID algorithm. The UUID is encoded as a string of any ASCII character that is 16 characters long. cannot be used in a PostgreSQL database
Native (local)
Choose identity, Sequence, or one of Hilo based on the ability of the underlying database. (Detailed: Hibernate automatically uses one of identify, Hilo, and sequence as the primary key generation method based on the definition in the database adapter)
Assigned (Program Settings)
Let the application assign an identifier to the object before save (). (Supplement: The primary key is generated by the use of logic, the data is left to hibernate, the primary key value has been set, no hibernate intervention)
Foreign (external reference)
Use an identifier for another associated object. Use with the <one-to-one> Union!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.