简体   繁体   English

EclipseLink和H2策略= GenerationType.AUTO

[英]EclipseLink and H2 strategy = GenerationType.AUTO

I'm using EclipseLink and H2 and I have set the strategy to 我正在使用EclipseLink和H2,并且已将策略设置为

strategy = GenerationType.AUTO

because IDENTITY strategy didn't work (it tried to insert a NULL id and failed). 因为IDENTITY策略不起作用(它试图插入NULL ID并失败)。

Now I don't know what the AUTO type uses but it seems to work, the ids given are however a bit random while I'd like them to start from 1 and increase at steps of 1 when possible. 现在我不知道AUTO类型使用什么,但它似乎可以工作,但是给定的id有点随机,而我希望它们从1开始并在可能的情况下以1的步长增加。

JPA however seems to insert 1,51,52,101,151 which is a little too random and I consider it a waste of numbers. 但是,JPA似乎插入了1,51,52,101,151,这有点太随意了,我认为这是浪费数字。 Even if it wasn't a waste (for instance because JPA also used the missing numbers between the gaps) I would like for the ids to be increasing and not random! 即使这不是浪费(例如,因为JPA也使用了间隔之间的缺失数字),但我还是希望id增加而不是随机的!

Any suggestion on how to set it so? 关于如何设置它的任何建议?

The default pre-allocation size in JPA is 50, you can set the allocationSize to change this increment to 1, although I would not recommend this, as this will make your performance much worse. JPA中的默认预分配大小为50,您可以设置allocationSize将此增量更改为1,尽管我不建议这样做,因为这会使您的性能大大降低。

You still should not get holes such as this. 您仍然不应该遇到这样的漏洞。 Are you creating a new EntityManagerFactory for every request? 您是否为每个请求创建一个新的EntityManagerFactory? (don't do this), or do you have multiple concurrent requests? (不这样做),或者您有多个并发请求? are you using JTA? 您在使用JTA吗?

IDENTITY does work with H2, ensure that you created your table with the correct IDENTITY type. IDENTITY确实适用于H2,请确保您使用正确的IDENTITY类型创建了表。 AUTO is defaulting to TABLE sequencing. AUTO默认为TABLE排序。 In general I do not recommend IDENTITY, as it does not support pre-allocation. 通常,我不建议使用IDENTITY,因为它不支持预分配。

暂无
暂无

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

相关问题 Hibernate @GeneratedValue(strategy = GenerationType.AUTO) - Hibernate @GeneratedValue(strategy = GenerationType.AUTO) GenerationType.AUTO没有选择适当的策略 - GenerationType.AUTO not picking appropriate strategy 使用 GenerationType.AUTO 的 h2 测试找不到序列“HIBERNATE_SEQUENCE” - Sequence "HIBERNATE_SEQUENCE" not found for h2 test with GenerationType.AUTO JPA @GeneratedValue(strategy=GenerationType.AUTO) 在 MySQL 上不起作用 - JPA @GeneratedValue(strategy=GenerationType.AUTO) does not work on MySQL 休眠Junit hsqldb-(strategy = GenerationType.AUTO)不起作用 - Hibernate Junit hsqldb - (strategy = GenerationType.AUTO) not working 休眠:在以下情况下插入具有自定义ID的实体:strategy = GenerationType.AUTO - Hibernate: inserting an entity with custom id in the case: strategy = GenerationType.AUTO oracle上的Hibernate序列,@ GeneratedValue(strategy = GenerationType.AUTO) - Hibernate sequence on oracle, @GeneratedValue(strategy = GenerationType.AUTO) 使用@GeneratedValue(strategy = GenerationType.AUTO)时,Hibernate不保存对象 - Hibernate does not save Object when using @GeneratedValue(strategy=GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO): MySQL 和表之间共享的生成ID? - @GeneratedValue(strategy = GenerationType.AUTO): MySQL and generated IDs shared between tables? 为什么GenerationType.AUTO在PostgreSQL上没有使用串口? - Why is GenerationType.AUTO not using a serial on PostgreSQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM