My sequences are not in the correct order

25 views
Skip to first unread message

Bruno Santos Silva

unread,
Aug 20, 2019, 9:02:39 AM8/20/19
to H2 Database
Good morning friends, I'm using h2 where I backup and restore my versions and created 2 tables to be compared to the database versions,
I'm having the following problem I'm using the sequence in one of the columns and these same sequences work normally until I stop the bank and start again, it ends up getting lost for example, when it stops at 12, I stop the bank and restart it goes to 30 or sometimes 130, how can i fix this error i'm using the latest version.

I am using liquibase and hibernate in my javafx application

I will put the database values : 

My url
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:h2:./db/eQRHDatabase;MV_STORE=FALSE;MVCC=FALSE

Model
@Entity
public class Database {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private int id;

@Column(name = "DATE")
private Timestamp date;

@Column(name = "VERSION_DB")
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private int versionDB;
}

Liquibase :

create TABLE DATABASE (
ID INTEGER not null AUTO_INCREMENT,
DATE timestamp AS CURRENT_TIMESTAMP,
VERSION_DB INTEGER not null AUTO_INCREMENT,
PRIMARY KEY (ID)
);
-- rollback DROP TABLE DATABASE;


Noel Grandin

unread,
Aug 20, 2019, 9:07:51 AM8/20/19
to h2-da...@googlegroups.com
Sequences are not specified to be continuous, they can have gaps, and on some databases they can even be allocated out
of order.

Bruno Santos Silva

unread,
Aug 20, 2019, 10:01:30 AM8/20/19
to H2 Database

Do you have an option to enable this on h2?

Evgenij Ryazanov

unread,
Aug 20, 2019, 10:42:16 AM8/20/19
to H2 Database
Do you have an option to enable this on h2?
What exactly do you want to enable?

You can use
GENERATED BY DEFAULT AS IDENTITY (CACHE 1)
instead of
AUTO_INCREMENT
to disable the cache of the sequence. The default cache size is 32. Cached identities may be lost on abnormal termination of the process.

However, you should check why your application does not shutdown the database properly.
Reply all
Reply to author
Forward
0 new messages