Questions tagged [h2]
1370 questions
1
votes
2
answer
36
Views
How to enable H2 Database Server Mode in Spring Boot
I'm using a H2 database with a file using Spring Boot.
In my application.properties, I have this entry:
spring.datasource.url=jdbc:h2:file:c:/Testprojekte/spring-boot-h2-db
But now I would like to be able to look at the database while running the application, which currently isn't possible because I...
1
votes
2
answer
1.1k
Views
H2 determining if String value is numeric
This is my first time using H2 and I'm trying to select only the records that DO NOT have a numerical ID (e.g. H27384WK would be valid, but 398453 would not). After researching this online, I couldn't find any solutions for this and none of the functions mentioned here seem to be helpful. How could...
1
votes
1
answer
49
Views
H2 database storage mechanism
I have used H2 database for my junit tests and it works perfectly fine.
However, I have few questions regarding it's persistence properties:
What happens when I switch off my laptop? Are the tables and data lost in case of any restart? If yes, is there any restore possible?
Does H2 uses transaction...
1
votes
0
answer
137
Views
H2 HEXTORAW gives chinese char output
I'm trying to write a dbunit test with the H2 database for a query using the HEXTORAW function
select hextoraw('79E6AAA933FA493990CC7502B5167D49')
gives me
秦ꪩ㏺䤹郌甂딖絉
as output on H2, the real oracle database where the code will run gives me
79 e6 aa a9 33 fa 49 39 90 cc 75...
1
votes
0
answer
96
Views
Error when trying to delete column that was part of dropped unique constraint
I'm trying to remove a column from a table.
Since that column is part of a unique constraint, I
first drop the constraint
and then try to drop the column
But I get: Column may be referenced by 'PUBLIC.UNIQUE_MYTABLE_INDEX_7';, with is the 'UNIQUE_INDEX_NAME' of the constraint that i previously just...
1
votes
2
answer
815
Views
Table not found with H2
My Java EE application cannot find tables. I am using WildFly (as the application server) and H2 (as the DB, in the embedded mode).
The error is:
org.h2.jdbc.JdbcSQLException: Table 'MY_TABLE' not found
Look at my table creation:
create table 'MY_TABLE' (
-- ...
);
See how my entity is defined:
@Ent...
1
votes
1
answer
404
Views
H2 add/subtract Interval Second in Oracle Query
I have h2 database in server mode for my tests.
I can't add/subtract an interval to my date, in my spring-batch writer, when my request works in SQLDeveloper
h2 config :
private DataSource createH2DataSource() {
String jdbcUrl = String.format('jdbc:h2:%s/target/db/h2;AUTO_SERVER=TRUE;MODE=Oracle', S...
1
votes
1
answer
511
Views
H2 Spring-Data - default value doesn't work
I'm trying to have a default value for one attribute, when I persist an object in H2 database with no value for this attribute.
Even with the right entity declaration, the default value is not persisted.
I would like to know why and how I can fix it, I isolated the problem in the code below :
appl...
1
votes
0
answer
34
Views
Spring, Hibernate annotation configuration - Dynamic
I have following requirement, where my application should be functioning either with H2 or Mysql database, based on a configuration in the application.properties file.
As a result, I should be able to attach dynamically the correct Hibernate Sequence generator or Identity generator for the primary k...
1
votes
0
answer
97
Views
Configure OM2M to connect to the server
https://wiki.eclipse.org/OM2M/one/Advanced_DB
I am developing an IoT project based on Eclipse OM2M project. I've been trying to do the same thing as the tutorial above did in the 'Run H2 in another mode' part. In the tutorial, it said that the default database(h2) was running in embedded mode. My go...
1
votes
1
answer
502
Views
H2 DB Url error
I have the following H2 datasource configuration
jdbc.driverClassName=org.h2.Driver
jdbc.url=jdbc:h2:mem:test;INIT=CREATE SCHEMA IF NOT EXISTS TESTSCHEMA\;RUNSCRIPT FROM '~/schema-test.sql'\;RUNSCRIPT FROM '~/data-test.sql';DB_CLOSE_DELAY=-1
jdbc.user=xyzapp
jdbc.pass=x161jq3
When I run it, I'm gett...
1
votes
0
answer
149
Views
how to properly save an instant on a h2 database?
I am using h2 and im new at it.
Currently I am trying to save an Instant object (I made it from an epoch with milliseconds) on my h2 table that is defined like this:
CREATE TABLE transac (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
time TIMESTAMP WITH TIME ZONE NOT NULL,
PRIMARY KEY (id)
);
I also trie...
1
votes
1
answer
241
Views
database.models.Employee is NOT an Entity Bean registered with this server?
I'm trying to use Play Framework with h2 database, using Ebeans, to create a simple employee management site, but I just can't seem to get it working. The error I've been hit with is:
Error injecting constructor, javax.persistence.PersistenceException: database.models.Employee is NOT an Entity Bean...
1
votes
1
answer
209
Views
Mysql SQL query DATEDIFF failed in H2 where mode was MYSQL
Background: In one of my projects I am doing component testing on Spring Batch using JUnit. Here application DB is MYSQL. In Junit test execution I let the data-source switch between
MYSQL and
H2(jdbc:h2:mem:MYTESTDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL)
based on configuration....
1
votes
0
answer
171
Views
Spring Boot H2 console webServlet not registered by autoconfiguration
I have a very simple SpringBoot 'app' demo with H2 in its dependencies. It's packed in demo.jar.
I can run it from the command line with java -jar demo.jar and it starts.
Then I can go to http://localhost:8080/h2 and H2 console is displayed.
This is on Windows.
Now - when I use exactly the same j...
1
votes
0
answer
247
Views
H2 connexion closed even if DB_CLOSE_DELAY=-1
I have this H2 url on my application.properties:
spring.datasource.url=jdbc:h2:mem:myschema;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS myschema;MV_STORE=FALSE;MVCC=FALSE
spring.datasource.driver-class-name=org.h2.Driver
spring.h2.console.enabled=true
spring.h2.console....
1
votes
0
answer
56
Views
MVStore Online Back Up
The information in the MVStore docs on backing up a database is a little vague, and I'm not familiar with all the concepts and terminology, so I wanted to see if the approach I came up with makes sense.
I'm a Clojure programmer, so please forgive my Java here:
// db is an MVStore instance
FileStore...
1
votes
0
answer
626
Views
Unable to build Hibernate SessionFactory - missing sequence
I'm trying to test my REST API, with Hibernate and H2, and I'm getting PersistenceException :
javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(En...
1
votes
0
answer
577
Views
How to run h2 db as standalone server with custom username/password?
I have used h2 db as an embedded database for some java applications in the past but this time I would like to run it as a standalone server (tcp) to which I can connect from another client changing the default user and password
I downloaded h2db, unzipped the zip and I saw in the bin directory the...
1
votes
1
answer
653
Views
H2 junit test not creating table and not populating data
Just experimenting with using H2 as a testing database for unit tests. The app works but failing to find the schema-h2.sql file in src/test/resources. The error:
ServletContext resource [/schema-h2.sql] defined by 'spring.datasource.schema' does not exist
I can define it this way in src/test/resour...
1
votes
0
answer
232
Views
How to close H2 SQL with all it's background threads (MVStore)
During memory allocation optimization process for Java application that use embedded H2SQL v1.4.196 i noticed that even after closing all H2 database connections (via 'Connection.close()') and even after trying to execute 'SHUTDOWN' statement, there is still one background H2 thread running - 'MVSto...
1
votes
1
answer
623
Views
Why doesn't Hibernate use the H2 DB's sequence?
I am using Hibernate 5.2.15 and a H2 database (version 1..4.197). I have created a sequence with
CREATE SEQUENCE SEQ_PRIMARYKEY START WITH 1 INCREMENT BY 1;
and my entity looks like
@Entity
@Table(name='Payment',
uniqueConstraints={@UniqueConstraint(columnNames={'ID'})})
public class Payment {
@Id...
1
votes
3
answer
73
Views
SQL to get top 3 from a table with at least one from opposite gender
I have a database table like this
Users
id Capacity Gender
----------------------
1 10 M
---------------------
2 9 M
---------------------
3 4 F
---------------------
4 8 M
---------------------
5 7 F
---------------------
And I want to retrieve the top 3...
1
votes
0
answer
114
Views
H2 database with corrupted table
We have an H2 database with what looks to be a corrupted table. Using the H2 web console, we are able to run SELECT * queries on all the tables except one. For this one table, TBL_TRANSACTION, we get the error result:
SELECT * FROM TBL_TRANSACTION;
General error: 'java.nio.BufferUnderflowException...
1
votes
1
answer
617
Views
Spring Boot Application Tests with H2 Database and Flyway Fails to Seed
I have an application I am trying to test using H2.
Here's my application.yml:
spring:
datasource:
url: jdbc:h2:mem:appdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
jpa:
database-platform: org.hibernate.dialect.H2Dialect
flyway:
url: jdbc:h2:mem:appdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
user:...
1
votes
0
answer
117
Views
Migrate h2 database to a postgresql docker in java spring
As titled, I am trying to migrate my h2 database to a postgres docker.
I made a dump of my h2 database using the command
SCRIPT TO 'fileName'
I then copied the file to my docker through the docker cp command. After that, I created a new database, and I tried launching
psql realdb < myfile.sql
which...
1
votes
0
answer
92
Views
H2 password issue after Upgrading to Hibernate 5
I've just upgraded my project from Hibernate 4.2.8 to Hibernate 5.2.12.Final
The only change in terms of configuration is the persistence provider, instead of org.hibernate.ejb.HibernatePersistence it's now org.hibernate.jpa.HibernatePersistenceProvider.
All of a sudden my Unit Tests which use H2 fa...
1
votes
0
answer
166
Views
Spring Boot: 2 in-memory databases, first one initialized by flyway, second manually
I have two H2 databases in my Spring boot application. Each of these databases is responsible for persistence of different entities.
The first one is initialized by Flyway which works fine, but now I need to initialize the other H2 database. I think I have found out that it is impossible to initiali...
1
votes
0
answer
52
Views
jMock test case for Spring JDBC template operations
I am using Spring and JDBC to insert into an Oracle Database using NamedParameterJdbcOperations. I got an error when I tried to write a test case for this operation using jMock and in-memory h2 database
CREATE TABLE DIM_ATTRIBUTE
(
ATTRIBUTE_ID VARCHAR2(45) NOT NUL...
1
votes
1
answer
476
Views
Getting SQL Syntax Error when loading schema.sql file in Spring Boot
I have a pretty basic schema.sql file:
Ideally, I just want the tables to auto-generate. I've disabled the auto ddl setting in my application.properties. However, I am getting errors:
Error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource...
1
votes
0
answer
170
Views
how to restore h2 database in java
How to restore a backup of h2 database in java. I store the backup on
statement.execute(String.format('SCRIPT TO '%s'','path.sql'));
but I don't know how to restore this backup I tried
statement.execute(String.format('RUNSCRIPT FROM '%s'', 'path.sql'));
but it gives me an error:
org.h2.jdbc.JdbcSQL...
1
votes
0
answer
256
Views
Error with type in base H2 for Instant type with Java 8
I have an entity
public class UserEntity {
...
@Basic(optional = false)
@Column(name = 'created', nullable = false, updatable = false)
@CreatedDate
private Instant created;
@Basic
@Column(name = 'modified_date', nullable = false)
@LastModifiedDate
private Instant modifiedDate;
...
}
I create the tab...
1
votes
1
answer
157
Views
hibernate.hbm2ddl.auto does not link sequence to id column
Question
Why I get NULL not allowed for column 'ID' exception when I execute INSERT INTO PUBLIC.MY_ENTITY (name) VALUES ('test name');?
Setup
I'm using Spring Boot and Hibernate. Spring Boot is launched with properties:
hibernate.hbm2ddl.auto=update
spring.jpa.hibernate.ddl-auto=update
I have entit...
1
votes
0
answer
118
Views
Spring boot test how to import data.sql just once during of h2 testing
I want to test my spring boot application via h2 in memory database where I would like to use:
spring.jpa.hibernate.ddl-auto: update
However, once I want to run tests with this command:
mvn clean test
it will show some errors which are related to constraint violations (ID must be unique).
These one...
1
votes
1
answer
414
Views
How to map an id column from a H2 database in java
I am trying to create a data table and map this table to an entity using a H2 in-memory database. I am using spring-boot (release 2.0.2) and flyway to create the database before running.
For some reason I am not successful to map the identity column when hibernate is to validate against the schema....
1
votes
1
answer
49
Views
Id not saved automatically in spring boot
I am creating a simple program in spring boot using JPA to show student and phone number relationship.
CODE
Student Entity
package student.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import ja...
1
votes
0
answer
246
Views
java spring H2 merge sql syntax error
I cant figure out what is wrong with this merge statement. It was working fine then I added COL2 in the statement, following the same pattern I believed but I get this error which seems to indicate it comes from aliasing the table?
Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statem...
1
votes
0
answer
70
Views
jump-ahead clocks with Oracle timestamps on Java 10
We have an application that has unit tests using H2 and integration tests using Oracle 11. All tests were passing using Java 8. We have a Foo table that has a created_at timestamp using SQL DDL created_at TIMESTAMP DEFAULT SYSTIMESTAMP NOT NULL, which we use both on Oracle and on H2 in Oracle mode....
1
votes
2
answer
500
Views
“SQLServerException: String or binary data would be truncated” issue - Configured H2 DB to diagnose but column size change not taking effect?
What?
When investigating an SQLServerException: String or binary data would be truncated issue in a Java Spring Boot app, I configured H2 as an alternative to give me some better diagnostic error messages and more flexibility in recreating the scenario.
TLDR?
Skip to And the problem is...
How did...
1
votes
2
answer
398
Views
spring.h2.console.settings.web-allow-others not working for me to disable access
I am trying to set spring.h2.console.settings.web-allow-others=false so that the console is only available on the local machine. It works great if I run my application in IntelliJ, but as soon as I build the jar and run it, this setting seems to have no effect and defaults to enabled.
I don't belie...