java-entity class UUID annotation configuration and method for generating IDs using UUID

Source: Internet
Author: User
Tags local time unique id

1 // discover Asset Primary key 2     @Id3     @GeneratedValue (generator= "System-uuid")4     @ Genericgenerator (name= "System-uuid", strategy= "UUID")5     private Long ID;   

The GUID is a 128-bit long number, typically represented by a 16 binary. The core idea of the algorithm is to combine the machine's NIC, local time, and a random number to generate the GUID. Theoretically, if a machine produces 10 million GUIDs per second, it can be guaranteed (in a probabilistic sense) that it will not repeat for 3,240 years.

The UUID is a new class in 1.5 that, under Java.util, can produce a globally unique ID.

The UUID (universally unique Identifier) Globally unique identifier, which is a number generated on a machine that guarantees that all machines in the same time and space are unique. Based on the standard calculations developed by the Open Software Foundation (OSF), Ethernet card addresses, nanosecond time, chip ID codes, and many possible numbers are used. A combination of the following: the current date and time (the first part of the UUID is related to the time, if you generate a UUID after a few seconds, the first part is different, the rest is the same), the clock sequence, the globally unique IEEE Machine identification number (if there is a network card, from the network card, No network cards are available in other ways, the only drawback to the UUID is that the resulting string will be longer.

1         //4cdbc040-657a-4847-b266-7e31d9e2c3d92          for(inti=0;i<5;i++){3UUID UUID =Uuid.randomuuid ();4String str =uuid.tostring ();5             //Remove the "-" in the UUID6String temp = str.substring (0, 8) + str.substring (9, +) + str.substring (+) + str.substring (+ +) + str.substring (2 4);7             //System.out.println (str + "= =" + temp + "uuid.hashcode ()-" + Uuid.hashcode ());8             //get the hashcode of the UUID9             intA =Uuid.hashcode ();Ten             //absolute value of hashcode because the hashcode of the UUID may be negative One             intb =Math.Abs (a); ASystem.out.println (A + "==========" +b); -}

java-entity class UUID annotation configuration and method for generating IDs using UUID

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.