lia*_* xu 3 java oracle jpa h2
我在谷歌上搜索了很多,发现很多人在https://www.logicbig.com/tutorials/java-ee-tutorial/jpa/seq-generator.html 中说的allocationSize意思是 ' After 'allocationSize' is reached, the next id will be retrieved from the database sequence again' 。
它的意思是 jpa 文件。
The amount to increment by when allocating sequence numbers from the sequence
Run Code Online (Sandbox Code Playgroud)
它似乎与sql中的“增量”相同。
哪一个是对的?由于我在h2/jpa中测试过,这个allocationSize不起作用,即使设置为20,sequence的下一个值也不会增加20。
我也对 sql 中的“缓存”感到困惑。
总之,以下面为例。
CREATE SEQUENCE ITEM_ID_SEQ START WITH 1 INCREMENT BY 100 cache 30;
Run Code Online (Sandbox Code Playgroud)
INCREMENT BY 100、缓存 30和jpa的allocationSize 有什么区别。
谢谢。
这里是配置值的简短说明:
分配大小
To minimize round trips to the database server, IDs are allocated in groups. The number of IDs in each allocation is specified by the allocationSize attribute.
It is possible that some of the IDs in a given allocation will not be used. Therefore, this strategy does not guarantee there will be no gaps in sequence values.
The default is 50.
INCREMENT BY
Specify the interval between sequence numbers.
This integer value can be any positive or negative integer, but it cannot be 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.
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. The potential number of lost values is equal to the value of the CACHE parameter.
Conclusion
allocationSize and INCREMENT BY must have the same value. A higher number reduces the database round trips.
Cache is DB performance optimization and is not available for all database types.
| 归档时间: |
|
| 查看次数: |
3521 次 |
| 最近记录: |