What's the reason behind the jumping GeneratedValue(strategy=GenerationType.TABLE) when not specifyi

Posted by joeduardo on Stack Overflow See other posts from Stack Overflow or by joeduardo
Published on 2010-05-24T06:48:34Z Indexed on 2010/05/24 6:51 UTC
Read the original article Hit count: 175

Filed under:
|
|

Why do I need to add allocationSize=1 when using the @TableGenerator to ensure that the id wouldn't jump from 1, 2,... to 32,xxx, 65,xxx,... after a jvm restart?

Is there a design reason for the need to specify the allocationSize?

This snippet would produce the jumping ids

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

Here's the modified snippet that produces the properly sequenced ids

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "account_generator")
@TableGenerator(name = "account_generator", initialValue = 1, allocationSize = 1)
private Long id;

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate