Several primary key generation policies of Hibernate and several primary keys of hibernate

Source: Internet
Author: User

Several primary key generation policies of Hibernate and several primary keys of hibernate

Primary Key type:
Business primary key (natural key): the value of the business primary key is derived from a business data.
Proxy primary key: the proxy primary key must generate a unique value.

Proxy primary key generation policy:
1. hibernate's primary key generation policy can only be used for proxy primary keys
2. Different primary key generation policies require different content.

The primary key generation policy of Hibernate:

1. assigned: The primary key identifier generated by the application. Generally, no proxy primary key is used in the database. The primary key is related to the business, that is, the Business primary key is used. This primary key generation method is not recommended. The proxy primary key should be used during database table design and the Business primary key should not be used. If no tag is specified, the assigned primary key is generated by default. When data is inserted, the primary key is generated by the user. Hibernate does not generate the primary key.

<Id name = "userid" type = "java. lang. long "> <column name =" USERID "precision =" 22 "scale =" 0 "/> <generator class =" assigned "/> </id>

2. identity: Applicable to MySQL, DB2, and ms SQL Server. It uses the primary key generated by the database to generate unique identifiers for long, short, and int types.
The auto-increment fields of SQL Server and MySQL cannot be stored in Oracle. Oracle does not support auto-increment fields.

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.