In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you the example analysis of the Hibernate primary key, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Introduction to Hibernate primary key
1.Assigned
In Assigned mode, the primary key value is generated by the program, and it must be specified before save (), otherwise an exception will be thrown
Features: the generated value of the primary key is completely determined by the user and has nothing to do with the underlying database. The user needs to maintain the primary key value and specify the primary key value before calling session.save ().
2.Hilo
Hilo uses the high-low algorithm to generate the primary key, and the high-low algorithm uses a high-order value and a low-order value, and then splices the two values obtained by the algorithm as the primary key in the database. The Hilo approach requires additional database tables and fields to provide a source of high values. The table used by default is
Hibernate_unique_key, the default field is called next_hi. Next_hi must have a record or an error will occur.
Features: additional database table support is required to ensure the * nature of the primary key in the same database, but not between multiple databases. The Hilo primary key generation method is maintained by Hibernate, so the Hilo method has nothing to do with the underlying database, but the values of the tables used by the hi/lo algorithm should not be manually modified, otherwise it will cause repeated primary key exceptions.
3.Increment
The Increment mode automatically increases the primary key value to generate a new primary key value, but requires the underlying database to support Sequence. Such as Oracle,DB2, etc. You need to add the setting of the Increment marker to the mapping file xxx.hbm.xml.
Features: maintained by Hibernate itself, suitable for all databases, not suitable for multiple processes to update the database concurrently, suitable for a single process to access the database. Cannot be used in a cluster environment.
4.Identity
At that time, Identity supported automatic growth based on the underlying database, and different databases used different primary key growth methods.
Features: related to the underlying database, the database is required to support Identity, such as auto_increment in MySQl and Identity in SQL Server. The supported databases are MySql, SQL Server, DB2, Sybase and HypersonicSQL. Identity does not need the interference of Hibernate and users, so it is more convenient to use, but it is not easy to migrate programs between different databases.
5.Sequence
Sequence requires the underlying database to support Sequence, such as Oracle database.
Features: the underlying database needs to support sequences, and the databases that support sequences include DB2, PostgreSql, Qracle, SAPDb and other databases to migrate programs between different databases, especially from databases that support sequences to databases that do not support sequences need to modify configuration files
6.Native
Native primary key generation method automatically selects Identity, Sequence and Hilo primary key generation methods according to different underlying databases.
Features: different primary key generation methods are adopted according to different underlying databases. Because Hibernate uses different mapping methods according to the underlying database, it is easy to migrate programs, which can be used when multiple databases are used in a project.
7.UUID
UUID uses the 128bit UUID algorithm to generate the primary key, which can guarantee the primary key in the network environment, and also can guarantee the primary key in different databases and different servers.
It can guarantee the primary key in the database, and the generated primary key takes up more storage space.
8.Foreign GUID
Foreign is used in one-to-one relationships. GUID primary key generation method uses a special algorithm to ensure the * * nature of generating primary key, and supports SQL Server and MySQL. The Hibernate primary key is described above.
The above is all the contents of the article "sample Analysis of Hibernate Primary Keys". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.