5

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

2

1 Answer 1

4

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).

Sign up to request clarification or add additional context in comments.

5 Comments

i dropped the hibernate_sequence.But how i can i create it again. I expected it should be created automatically when app server restarts
Why did you drop it when I said "update the sequence".
Probably, check your oracle manual on how to alter sequences.
@Kayaman I have @Id @Basic(optional = false) @GeneratedValue(strategy=GenerationType.AUTO) private Integer id; I get java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist. Error Code: 942. Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?. Please help.
@Kayaman I, also, tried with @GeneratedValue, but I get same previous result. I'm using Eclipse as JPA persistence provider.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.