Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give starting value to auto increment in hibernate

I am new to hibernate. How do I specify in Hibernate the starting value of my ID (say 100000) and auto increment the ID starting at this value in my code. Any help on this is appreciated.

@Id
@Column (name = "ID")
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy = "increment")
private Integer ID;
like image 938
user57358 Avatar asked Jan 25 '13 16:01

user57358


2 Answers

Try this: http://www.java2s.com/Code/Java/JPA/SetInitialValueOfTableGenerator.htm

JPA has a @TableGenerator annotation in which you can set an initial value.

like image 126
Sotirios Delimanolis Avatar answered Oct 27 '22 09:10

Sotirios Delimanolis


I found a way around this. I manually entered a row in the database with ID 1000000 and used the code mentioned in my question. The next time a add a record to this table, it takes 1000000 as the last value and starts incrementing from this value. Thanks for your help.

like image 30
user57358 Avatar answered Oct 27 '22 08:10

user57358