JPA primary key auto generate

Viewed 106869

my primary key entity look like below

@GeneratedValue(strategy= GenerationType.TABLE)
private Long id;

when i run, i get error

could not get or update next value;nested exception is org.hibernate.exception.SQLGrammerException:could not get or update next value

but when i just change to

@GeneratedValue 
private Long id;

no error throw . I want to generate unique primary key per table on oracle db .

3 Answers

IDENTITY: Autoincrement on-demand, efficient due to database internal lightweight locking but does not work very well with hibernate due to “transactional write-behind” flushing strategy adopted by Hibernate.

SEQUENCE: preallocate values to improve performance, supports well hibernates “transactional write-behind” flushing strategy.

TABLE (SEQUENCE): One or multiple tables can be used to hold the identifier sequence counter. But it means trading write performance for database portability.

short summary of Auto Generation

Related