Generator properties of HBM in Hibernate

Source: Internet
Author: User
Tags db2 generator postgresql uuid

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 >

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.