user3198603
user3198603

Reputation: 5826

How does the hibernate GenerationType.AUTO work in Oracle?

Using 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 i.e 101 (max + 1). But inserting some values available in between like 90. I am not sure how its possible ?

Does Hibernate internally create some database sequence and use then use last created value plus 1

Upvotes: 5

Views: 7845

Answers (1)

Kayaman
Kayaman

Reputation: 73558

For oracle, yes it creates a sequence (probably named 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).

Upvotes: 4

Related Questions