简体   繁体   English

jpa @ SequenceGenerator.allocationSize是什么意思?

[英]What does the jpa @SequenceGenerator.allocationSize mean?

I googled a lot and found many people said the allocationSize means ' After 'allocationSize' is reached, the next id will be retrieved from the database sequence again ' in https://www.logicbig.com/tutorials/java-ee-tutorial/jpa/seq-generator.html . 我用Google搜索了很多,发现很多人说allocationSize意味着“ After 'allocationSize' is reached, the next id will be retrieved from the database sequence again在” https://www.logicbig.com/tutorials/java-ee-tutorial /jpa/seq-generator.html

The the jpa document it means. 这意味着jpa文件。

The amount to increment by when allocating sequence numbers from the sequence

It seems it is the same as the 'increment by' in sql. 似乎它与sql中的'increment by'相同。

Which one is right? 哪一个是对的? Since I tested in h2/jpa, this allocationSize does not work, even it set it to 20, the next value of sequence does not increase by 20. 由于我在h2 / jpa中进行了测试,因此即使将其设置为20,此distributionSize也不起作用,序列的下一个值不会增加20。

I also confused about the 'cache' in sql. 我也对sql中的“缓存”感到困惑。

In summary, take below for example . 综上,以下面为例。

CREATE SEQUENCE ITEM_ID_SEQ START WITH 1 INCREMENT BY 100 cache 30;

What's the difference of the INCREMENT BY 100 , cache 30 , and the allocationSize of jpa . INCREMENT BY 100cache 30jpa分配大小有什么区别?

thanks. 谢谢。

Here a short explanation of the configuration values: 以下是配置值的简短说明:

allocationSize allocationSize

To minimize round trips to the database server, IDs are allocated in groups. 为了最大程度地减少与数据库服务器的往返行程,将ID分组分配。 The number of IDs in each allocation is specified by the allocationSize attribute. 每个分配中的ID数由distributionSize属性指定。

It is possible that some of the IDs in a given allocation will not be used. 给定分配中的某些ID可能不会被使用。 Therefore, this strategy does not guarantee there will be no gaps in sequence values. 因此,此策略不能保证序列值中没有间隙。

The default is 50. 默认值为50。

INCREMENT BY 增加

Specify the interval between sequence numbers. 指定序列号之间的间隔。

This integer value can be any positive or negative integer, but it cannot be 0. 该整数值可以是任何正整数或负整数,但不能为0。

If this value is negative, then the sequence descends. 如果该值为负,则序列下降。 If the value is positive, then the sequence ascends. 如果该值为正,则序列递增。 If you omit this clause, then the interval defaults to 1. 如果省略此子句,则间隔默认为1。

CACHE CACHE

Specify how many values of the sequence the database preallocates and keeps in memory for faster access. 指定数据库预先分配并保留在内存中的序列值的数量,以加快访问速度。

If a system failure occurs, all cached sequence values that have not been used in committed DML statements are lost. 如果发生系统故障,则所有在提交的DML语句中未使用的缓存序列值都会丢失。 The potential number of lost values is equal to the value of the CACHE parameter. 可能丢失的值的数量等于CACHE参数的值。

Conclusion 结论

allocationSize and INCREMENT BY must have the same value. assignmentSize和INCREMENT BY必须具有相同的值。 A higher number reduces the database round trips. 较高的数量可减少数据库往返次数。

Cache is DB performance optimization and is not available for all database types. 缓存是数据库性能的优化,并非对所有数据库类型都可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM