Connecting to H2 gives: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation:

1.3k Views Asked by At

Trying to connect to a H2 database using the generic command line using h2-1.4.197.jar, this H2 file database is from a Geonetwork 3.2 instance.

Using the following string: java -cp h2*.jar org.h2.tools.Shell -user "admin" -password "gnos" -url "jdbc:h2:~/git/geonetwork/geonetwork" -driver org.h2.Driver -sql "SELECT 1"

I obtain the following exception: Exception in thread "main" org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement: ALTER TABLE PUBLIC.CATEGORIESDES ADD CONSTRAINT PUBLIC.FK_69P88C8991LETUOQ16JDDI307 FOREIGN KEY(IDDES) REFERENCES PUBLIC.CATEGORIES(ID) NOCHECK [23505-197]

Question: Why is this violation happening and how it could be solved ???

1

There are 1 best solutions below

0
On

Using the h2 jar from Geonetwork (h2-1.3.174.jar) allowed to access the database:

java -cp h2-1.3.174.jar org.h2.tools.Shell -user "admin" -password "gnos" -url "jdbc:h2:~/git/geonetwork/geonetwork" -driver org.h2.Driver -sql "SELECT 1" 1 1 (1 row, 4 ms)

The problem was cause by an incorrect h2 version