In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article "Jspxcms primary key generation mechanism is what" most people do not understand, so the editor summarized the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "Jspxcms primary key generation mechanism is what" article it.
Database primary key generation strategies usually have
Self-increment primary key. Depending on the function of the database, mysql and sqlserver have the function of self-increasing primary key, while oracle and db2 do not.
Database sequence. Depending on the function of the database, mysql has no sequence.
UUID . Do not rely on the database. A 32-bit non-repeating string is generated by the program. Because the string is too long, it is easy to affect database performance as a primary key.
Table policy. Use a separate database table to record the primary key values of other tables, mimicking the function of database sequences.
Among them, the Table strategy has good versatility and can be used in any database. In Jspxcms, the name of the table is hibernate_sequences (version 7. 0 and earlier is t_id_table). The table name and its corresponding ID value are recorded respectively.
There are comments on how ID is generated in the domain entity class in the code. Take com.jspxcms.core.domain.Info as an example:
Id @ Column (name = "f_info_id", unique = true, nullable = false) @ TableGenerator (name = "tg_cms_info", pkColumnValue = "cms_info", initialValue = 1, allocationSize = 10) @ GeneratedValue (strategy = GenerationType.TABLE, generator = "tg_cms_info") public Integer getId () {return this.id;}
Where initialValue is the starting value of the primary key and allocationSize is the number of ID obtained by JPA at a time. Because getting ID consumes performance, instead of inserting a piece of data to get an ID, you get 10, 50, 100, or more at once. This can lead to ID discontinuity, such as getting 10 ID at a time, only one or two are used, the program is restarted, and the remaining eight or nine ID are invalidated.
If third-party programs want to insert data into these tables, they should pay close attention to the problem of ID. You need to modify the ID value in the hibernate_ sequences table, otherwise it will lead to an exception that causes a primary key conflict.
It is important to note that the next_val (ID value) in hibernate_sequences is actually using ID+2*allocationSize. For example, if the ID value currently used is 100 and the allocationSize is 10, then the next_val in the ID table seems to be 110, but it is actually 120.
You need to be very careful when you modify the next_val of hibernate_sequences. When you see that next_val is 100, you can use 101as your ID, but you should change next_val to a larger value, not to 102or 11010, but to 120th (when allocationSize is 10). The default value of allocationSize is 50, and the program will set this value even higher if you need to insert a lot of data. So don't be afraid to waste the ID value, it's always safe to make the next_val a little bigger.
The above is about the content of this article on "what is the primary key generation mechanism of Jspxcms". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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.