Questions tagged [h2]

H2 is a relational database management system written in Java. It can be embedded in Java applications or run in the client-server mode. H2 supports regular disk-based as well as in-memory databases.

The software is available as open source software under modified versions of the Mozilla Public License or the original Eclipse Public License. The main features of H2 are:

  • Very fast, open source, JDBC API
  • Embedded and server modes; in-memory databases
  • Browser based Console application
  • Small footprint: around 2 MB jar file size

The main author of H2 is Thomas Mueller, who also developed the Java database engine Hypersonic SQL. The name H2 stands for Hypersonic 2, however H2 does not share code with Hypersonic SQL or HSQLDB.

Wiki

Issues

API

4948 questions
16
votes
2 answers

Spring Testing with H2 db configuration

I use Oracle in production environment and I would like to use H2 for testing. I can type;
asyard
  • 1,743
  • 5
  • 21
  • 43
16
votes
1 answer

Any easy way to generate a build script from an H2 database?

let's image that one creates an H2 database with table, indexes, etc... Is there an easy way to extract a SQL script to recreate the structure of this database in another H2 database? I am not referring to the content of the tables, indexes, etc...…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
16
votes
9 answers

H2 Schema initialization. Syntax error in SQL statement

I have a spring boot application and I trying to initialize some data on application startup. This is my application properties: #Database…
Kirill
  • 1,540
  • 4
  • 18
  • 41
16
votes
3 answers

How to access *.mv.db file of H2 database?

I have created database with my own program and it appeared as mydatabase.mv.db file. But when I tried to access the same database with DbVisualizer, with apparently same parameters, it created two files mydatabase.lock.db and celebrity.h2.db and…
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
16
votes
4 answers

Spring Boot with Hibernate generating drop constraint errors on startup with H2 database

I am using spring-boot and have an H2 database configured like so (in the…
Aaron Zeckoski
  • 5,016
  • 8
  • 25
  • 48
16
votes
1 answer

H2 and Postgres array compatibility

Can I get h2 to support Postgres array syntax CREATE TABLE artists ( release_id integer, artist_name text, roles text[] ) I use h2 to mimic Postgres in my unit tests, but it doesn't like the above DDL because of the definition of roles (if I…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
16
votes
4 answers

Why am I getting a Primary Key violation for an @OneToMany property?

I have an entity: @Entity public class Student { @GeneratedValue(strategy = GenerationType.AUTO) @Id private long id; @OneToMany private Set courses; } When I try to persist the first entity of this type it works fine,…
Adam
  • 43,763
  • 16
  • 104
  • 144
16
votes
1 answer

Insert into h2 table if not exists

I am using H2. I want to insert a value into a table if it does not exist. I create the table with: CREATE TABLE IF NOT EXISTS $types (type VARCHAR(15) NOT NULL UNIQUE); And I want to do something like REPLACE INTO types (type) values…
Alison
  • 5,630
  • 4
  • 18
  • 26
16
votes
3 answers

Oracle MERGE statement in H2 database

We started to use the H2 in memory database for automated testing. We use Oracle for our production & dev environments. So the idea is to duplicate the table structure in H2 test-database as it is in our Oracle dev-database. The Oracle SQL…
user1877775
  • 201
  • 1
  • 2
  • 4
16
votes
5 answers

Stored Procedure in H2 Database

I am new to database and recently started writing test cases for H2 database. I want to know how to test a stored procedure in Eclipse. I have seen the following: http://www.h2database.com/html/features.html#user_defined_functions How to CREATE…
Abi
  • 1,335
  • 2
  • 15
  • 28
15
votes
4 answers

Start and setup in-memory DB using Spring

I'm writing a small demo application in Java using Spring, that needs to have access to a database. It should run on different machines and it would be far too much effort to setup a real database. Therefore I want to use an embedded one. The DB has…
martin
  • 2,150
  • 1
  • 34
  • 48
15
votes
2 answers

DATE_SUB and DATE_ADD in H2 for MySQL

I am using MySQL as my database and H2 for testing. I am also using playframework 2.3.x and Scala, but I think does not matter for the question purpose. H2 has a conflict with some functions that I am using in a query SELECT * FROM…
agusgambina
  • 6,229
  • 14
  • 54
  • 94
15
votes
4 answers

h2 (embedded mode ) database files problem

There is a h2-database file in my src directory (Java, Eclipse): h2test.db The problem: starting the h2.jar from the command line (and thus the h2 browser interface on port 8082), I have created 2 tables, 'test1' and 'test2' in h2test.db and I have…
aeter
  • 11,960
  • 6
  • 27
  • 29
14
votes
1 answer

h2 sql, create table with multi-column primary key?

How can i create a multi-column primary key within the CREATE TABLE statement using the h2 database? From my investigations, the code to do so in mySQL and Apache Derby databases is: CREATE TABLE SAMP.SCHED( CLASS_CODE CHAR(7) NOT NULL, DAY…
keithphw
  • 380
  • 1
  • 4
  • 14
14
votes
5 answers

How to replace enum type in H2 database?

MySQL dialect: CREATE TABLE My_Table ( my_column enum ('first', 'second', ... 'last')); H2 dialect: CREATE TABLE My_Table ( my_column ? ('first', 'second', ... 'last')); What type is equivalent in H2 too the enum type from MySQL?
Igor Kostenko
  • 2,754
  • 7
  • 30
  • 57