How to set the initial value for auto-zoom in sleep mode
I am new to hibernate. How do I specify in Hibernate the initial value of my id (say 100000) and automatically increment the id starting with that 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 @TableGenerator annotation where you can set the initial value.
I found a way to get 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 record is added to this table, it takes 1,000,000 as the last value and starts increasing from that value. Thanks for your help.
if the first required ID is 1000000 then use @TableGenerator, but if the first required ID is 1000001 then use @SequenceGenerator.
This article explains the difference in a very understandable way:
http://www.objectdb.com/java/jpa/entity/generated