Hibernate generator element

Source: Internet
Author: User

Hibernate generator element generates the primary key for new record. There are provided options provided by the generator method to be used in different situations.

 

The <generator> element

 

Here is the example

<Generator class = "assigned"/>


Here are the list of some commonly used generators in hibernate:

 

Generator Description
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. It shocould not the used in the clustered environment.
Identity It supports identity columns in DB2, MySQL, ms SQL Server, Sybase and hypersonicsql. The returned identifier is of type long, short or Int.
Sequence The sequence generator uses a sequence in DB2, PostgreSQL, Oracle, sap db, mckoi or a generator in InterBase. The returned identifier is of type long, short or int
HiLo The HiLo generator uses a hi/LO algorithm to efficiently generate identifiers of type long, short or Int, given a table and column (by default hibernate_unique_key and next_hi respectively) as a source of HI values. the HI/LO algorithm generates identifiers that are unique only for a particle database. do not use this generator with connections enlisted with JTA or with a user-supplied connection.
Seqhilo The seqhilo generator uses a hi/LO algorithm to efficiently generate identifiers of type long, short or Int, given a named database sequence.
UUID The UUID generate 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.
Guid It uses a database-generated guid string on ms SQL Server and MySQL.
Native It picks identity, sequence or HiLo depending upon the capabilities of the underlying database.
Assigned Lets the application to assign an identifier to the object before save () is called. This is the default strategy if no <generator> element is specified.
Select Retrieves a primary key assigned by a database trigger by selecting the row by some unique key and retrieving the primary key value.
Foreign Uses the identifier of another associated object. usually used in conjunction with a <one-to-one> Primary Key Association.

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.