Hibernate GeneratedValue从1开始虽然有一些数据

问题描述 投票:0回答:1

我正在开发一个spring-hibernate应用程序,该应用程序运行良好,直到我选择迁移到SQL Server以轻松导入一些数据

问题是在导入之后(ID列被数字填充到18,000),当我尝试向我的数据库添加另一行时,hibernate从1开始生成ID(我使用了Auto,Table,Sequence和Identity)

有这个问题的解决方案吗?

或者我应该从ID列的大值开始导入数据?

提前致谢。

java spring hibernate spring-boot hibernate-mapping
1个回答
0
投票

你可以使用这样的东西:

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

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

}
© www.soinside.com 2019 - 2024. All rights reserved.