简体   繁体   English

更改JPA实体ID生成策略

[英]Change JPA Entities Id Generation Streategy

There is a JSF/JPA application with EclipseLink2 which has about 40 different Entity classes. 有一个带有EclipseLink2的JSF / JPA应用程序,它具有大约40个不同的Entity类。 The method used to generate the id for every Entity class is AUTO. 用于为每个Entity类生成ID的方法是AUTO。

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;

After about one weeks run in production, the Id numbers has passed more than 10,000. 经过约一星期的生产,编号已超过10,000。 I am worries about the possibility of running out the long numbers in few years time. 我担心几年后可能会用完大量数据。

So I searched the net and changed the Id Generation Strategy as below. 因此,我在网上搜索并更改了ID生成策略,如下所示。

@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "item_entity_seq_gen")
@SequenceGenerator(name = "item_entity_seq_gen", sequenceName = "ITEM_ENTITY_SEQ")
Long id;

But when a new Entity is been created, there is an error as follows. 但是,当创建新实体时,会出现如下错误。

How can I change the auto generation strategy so that there will be no threat to running out of long ids after the development stage. 我该如何更改自动生成策略,以便在开发阶段之后不会威胁用完长ID。

Thanks in advance 提前致谢

正如评论中的isnot2bad所述,如果自动生成的ID几乎用完了,我已经放弃了生成单独ID的新方法。

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

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