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;

      

+3


source to share


3 answers


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



JPA has @TableGenerator annotation where you can set the initial value.

+1


source


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.



+3


source


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

0


source







All Articles