Primary Key Generation Policy

Source: Internet
Author: User

Primary Key Generation Policy

The value of <generator> can be:

1,Increment: Unique Identifier generated for long, short, or Int type. Data can be used only when no other process inserts data into the same table.

2,Identity: The returned identifier is of the long, short, or Int type. Support for built-in identifier fields for DB2, ms SQL Service, Sybase, and hypersonicsql

3,Sequence: Use sequence in DB2, PostgreSQL, Oracle, sapdb, and mckoi, and generator in InterBase ). The returned identifier is of the long, short, or Int type.

4,HiLo, seqhilo: Use a high/low level algorithm to efficiently generate long, short, or Int type identifiers

5,UUID: Use a 128-bit UUID algorithm to generate string-type identifiers, which are unique in a network (using IP addresses ). UUID is encoded as a 32-bit hexadecimal number string

6,Guid: Use the guid string generated by the database in ms SQL Server and MySQL

7,Native: Select one of identity, sequence, or HiLo Based on the capabilities of the underlying database.

8,Assigned: Assign an identifier to the object before saving. This is the default generation policy when the <generator> element is not specified.

9,Select: Use a database trigger to select rows with unique primary keys and return primary key values to allocate a primary key.

10,Foreige: Use the identifier of another associated object. Usually used together with <ont-to-one>

11,Sequence-indentity: A special sequence generation policy that uses database sequences to generate actual values. However, it is combined with getgeneratedkeys of jdbc3 so that the generated values are returned when the insert statement is executed.

 

1, 2, 7 can be used for MySQL

Exceptions are thrown when MySQL 3, 4, 5, 6, and 9 are used.

Note: All SQL statements used during verification are directly configured, for example:

<Generator class = "native"> </generator>

 

3 exceptions:

Org. hibernate. mappingexception: cocould not instantiate ID generator [entity-name = com. csdn. Products. domain. MERs]

At org. hibernate. Id. Factory. defaultidentifiergeneratorfactory. createidentifiergenerator (defaultidentifiergeneratorfactory. Java: 118)

Atorg. hibernate. Mapping. simplevalue. createidentifiergenerator (simplevalue. Java: 193)

Atorg. hibernate. impl. sessionfactoryimpl. <init> (sessionfactoryimpl. Java: 248)

Atorg. hibernate. cfg. configuration. buildsessionfactory (configuration. Java: 1872)

At com. csdn. Products. juint. Demo. Test (Demo. Java: 18)

At sun. Reflect. nativemethodaccessorimpl. invoke0 (native method)

At sun. Reflect. nativemethodaccessorimpl. Invoke (nativemethodaccessorimpl. Java: 39)

Atsun. Reflect. delegatingmethodaccessorimpl. Invoke (delegatingmethodaccessorimpl. Java: 25)

At java. Lang. Reflect. method. Invoke (method. Java: 597)

Atorg. JUnit. Runners. model. frameworkmethod $1. runreflectivecall (frameworkmethod. Java: 44)

Atorg. JUnit. Internal. Runners. model. reflectivecallable. Run (reflectivecallable. Java: 15)

Atorg. JUnit. Runners. model. frameworkmethod. invokeexplosively (frameworkmethod. Java: 41)

Atorg. JUnit. Internal. Runners. Statements. invokemethod. Evaluate (invokemethod. Java: 20)

Atorg. JUnit. Runners. blockjunit4classrunner. runchild (blockjunit4classrunner. Java: 76)

Atorg. JUnit. Runners. blockjunit4classrunner. runchild (blockjunit4classrunner. Java: 50)

At org. JUnit. Runners. parentrunner $ 3.run( parentrunner. Java: 193)

At org. JUnit. Runners. parentrunner $1. Schedule (parentrunner. Java: 52)

Atorg. JUnit. Runners. parentrunner. runchildren (parentrunner. Java: 191)

Atorg. JUnit. Runners. parentrunner. Access $000 (parentrunner. Java: 42)

At org. JUnit. Runners. parentrunner $2. Evaluate (parentrunner. Java: 184)

At org. JUnit. Runners. parentrunner. Run (parentrunner. Java: 236)

Atorg. Eclipse. jdt. Internal. junit4.runner. junit4testreference. Run (junit4testreference. Java: 49)

Atorg. Eclipse. jdt. Internal. JUnit. Runner. testexecution. Run (testexecution. Java: 38)

At org. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. runtests (remotetestrunner. Java: 467)

Atorg. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. runtests (remotetestrunner. Java: 683)

Atorg. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. Run (remotetestrunner. Java: 390)

Atorg. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. Main (remotetestrunner. Java: 197)

Caused by: org. hibernate. mappingexception: org. hibernate. dialect. mysqlinnodbdialect doesnot support Sequences

At org. hibernate. dialect. dialect. getsequencenextvalstring (dialect. Java: 603)

Atorg. hibernate. Id. sequencegenerator. Configure (sequencegenerator. Java: 101)

Atorg. hibernate. Id. Factory. defaultidentifiergeneratorfactory. createidentifiergenerator (defaultidentifiergeneratorfactory. Java: 111)

... 26 more

 

9 Exceptions:

Org. hibernate. Id. identifiergenerationexception: no natural-ID property defined; need to specify [Key] In generator parameters

Atorg. hibernate. Id. selectgenerator. determinenameofpropertytouse (selectgenerator. Java: 73)

At org. hibernate. Id. selectgenerator. Access $100 (selectgenerator. Java: 52)

Atorg. hibernate. Id. selectgenerator $ selectgeneratordelegate. <init> (selectgenerator. Java: 117)

Atorg. hibernate. Id. selectgenerator $ selectgeneratordelegate. <init> (selectgenerator. Java: 98)

At org. hibernate. Id. selectgenerator. getinsertgeneratedidentifierdelegate (selectgenerator. Java: 64)

Atorg. hibernate. persister. entity. abstractentitypersister. postconstruct (abstractentitypersister. Java: 3175)

Atorg. hibernate. persister. entity. singletableentitypersister. <init> (singletableentitypersister. Java: 439)

Atorg. hibernate. persister. persisterfactory. createclasspersister (persisterfactory. Java: 84)

Atorg. hibernate. impl. sessionfactoryimpl. <init> (sessionfactoryimpl. Java: 286)

At org. hibernate. cfg. configuration. buildsessionfactory (configuration. Java: 1872)

At com. csdn. Products. juint. Demo. Test (Demo. Java: 18)

At sun. Reflect. nativemethodaccessorimpl. invoke0 (native method)

Atsun. Reflect. nativemethodaccessorimpl. Invoke (nativemethodaccessorimpl. Java: 39)

At sun. Reflect. delegatingmethodaccessorimpl. Invoke (delegatingmethodaccessorimpl. Java: 25)

At java. Lang. Reflect. method. Invoke (method. Java: 597)

Atorg. JUnit. Runners. model. frameworkmethod $1. runreflectivecall (frameworkmethod. Java: 44)

At org. JUnit. Internal. Runners. model. reflectivecallable. Run (reflectivecallable. Java: 15)

Atorg. JUnit. Runners. model. frameworkmethod. invokeexplosively (frameworkmethod. Java: 41)

Atorg. JUnit. Internal. Runners. Statements. invokemethod. Evaluate (invokemethod. Java: 20)

Atorg. JUnit. Runners. blockjunit4classrunner. runchild (blockjunit4classrunner. Java: 76)

Atorg. JUnit. Runners. blockjunit4classrunner. runchild (blockjunit4classrunner. Java: 50)

At org. JUnit. Runners. parentrunner $ 3.run( parentrunner. Java: 193)

At org. JUnit. Runners. parentrunner $1. Schedule (parentrunner. Java: 52)

Atorg. JUnit. Runners. parentrunner. runchildren (parentrunner. Java: 191)

Atorg. JUnit. Runners. parentrunner. Access $000 (parentrunner. Java: 42)

Atorg. JUnit. Runners. parentrunner $2. Evaluate (parentrunner. Java: 184)

At org. JUnit. Runners. parentrunner. Run (parentrunner. Java: 236)

Atorg. Eclipse. jdt. Internal. junit4.runner. junit4testreference. Run (junit4testreference. Java: 49)

Atorg. Eclipse. jdt. Internal. JUnit. Runner. testexecution. Run (testexecution. Java: 38)

At org. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. runtests (remotetestrunner. Java: 467)

Atorg. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. runtests (remotetestrunner. Java: 683)

Atorg. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. Run (remotetestrunner. Java: 390)

Atorg. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. Main (remotetestrunner. Java: 197)

 

 

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.