[英]How does the hibernate GenerationType.AUTO work in Oracle?
Using oracle/JPA Hibernate. 使用oracle / JPA Hibernate。 I imported the schema which has values under student table in below fashion. 我以下面的方式导入了学生表下具有值的模式。 Here is the example 这是一个例子
100
85
80
70
1
I have below code: 我有下面的代码:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
long id;
Now when a new student is inserted , it does not inserts max value ie 101 (max + 1). 现在插入新学生时,它不会插入最大值,即101(最大+ 1)。 But inserting some values available in between like 90. I am not sure how its possible ? 但是在90之间插入一些可用的值。我不确定它是如何可能的?
Does Hibernate internally create some database sequence and use then use last created value plus 1 Hibernate是否在内部创建了一些数据库序列,然后使用最后创建的值加1
For oracle, yes it creates a sequence (probably named hibernate_sequence
). 对于oracle,是的,它会创建一个序列(可能名为hibernate_sequence
)。
If you have existing values in the table, you probably want to update the sequence to give you ids larger than the existing ones (otherwise you'll soon get primary key errors). 如果表中有现有值,则可能需要更新序列以使id大于现有值(否则很快就会出现主键错误)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.