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;
Try this: http://www.java2s.com/Code/Java/JPA/SetInitialValueOfTableGenerator.htm
JPA has a @TableGenerator annotation in which you can set an initial value.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With