简体   繁体   中英

Hibernate GeneratedValue starting from 1 although there are some data

I was developing a spring-hibernate app which worked well till I chose to migrate to SQL Server to import some data easily

The problem is after importing (the ID column was filled by numbers till 18,000), when I try to add another row to my database, hibernate generates ID beginning from 1 (I used Auto, Table, Sequence, and Identity)

Is there a solution for this problem ?

Or should I import the data starting from a big value for ID column ?

Thanks in advance.

You can use something like this:

@Entity
@SequenceGenerator(name="seq", initialValue=18000, allocationSize=100)
public class EntityWithSequenceId {

    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq")
    @Id long id;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM