3

So how exactly does the auto generate function "@GeneratedValue(strategy = GenerationType.AUTO)" work?

I'm brand new to Hibernate and have inherited a project that uses is extensively. The java object has:

@Id
@GeneratedValue(strategy = GenerationType.AUTO)    
@Column(name="ID")    
private Long id;

When I create a new entity of this type, the ID is generated. Subsequent new entities have IDs incremented by 2. Where exactly is this done?

Also, it generates different IDs on our DEV and TEST environments, so somehow it is database specific. Is there a 'feeder' table/view/sequence or something?

For example, if I wanted the generated IDs to start being 100,000,XXX as opposed to 10,XXX and increment by 100, how would I go about making that change?

Please help out a noob. Thanks in advance.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
user1435866
  • 51
  • 1
  • 5

1 Answers1

0

As mentioned, this is governed by your Oracle database. If the id's are incrementing by 2, it is because someone set it to 2. In oracle, SET INCREMENT BY will specify the increment on the identity column.

To change the seed value, you use RESTART WITH.

ALTER TABLE mytable ALTER COLUMN id SET INCREMENT BY 100    
ALTER TABLE mytable ALTER COLUMN id RESTART WITH 100000000

Oracle documentation for alter table: Alter table

bradleyfitz
  • 686
  • 4
  • 8