Hibernate GeneratedValue从1开始虽然有一些数据
Hibernate GeneratedValue starting from 1 although there are some data
我正在开发一个 spring-hibernate 应用程序,它运行良好,直到我选择迁移到 SQL 服务器以轻松导入一些数据
问题出在导入后(ID栏填满数字到18000),
当我尝试向我的数据库添加另一行时,hibernate 生成从 1 开始的 ID(我使用了 Auto、Table、Sequence 和 Identity)
这个问题有解决方案吗?
还是应该从 ID 列的大值开始导入数据?
提前致谢。
你可以这样使用:
@Entity
@SequenceGenerator(name="seq", initialValue=18000, allocationSize=100)
public class EntityWithSequenceId {
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq")
@Id long id;
}
我正在开发一个 spring-hibernate 应用程序,它运行良好,直到我选择迁移到 SQL 服务器以轻松导入一些数据
问题出在导入后(ID栏填满数字到18000), 当我尝试向我的数据库添加另一行时,hibernate 生成从 1 开始的 ID(我使用了 Auto、Table、Sequence 和 Identity)
这个问题有解决方案吗?
还是应该从 ID 列的大值开始导入数据?
提前致谢。
你可以这样使用:
@Entity
@SequenceGenerator(name="seq", initialValue=18000, allocationSize=100)
public class EntityWithSequenceId {
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq")
@Id long id;
}