h2

IntegrationTest isolation fails in springboot 2.2.2.RELEASE (Error dopping tables after each SpringBootTest)

元气小坏坏 提交于 2020-01-15 05:41:06
问题 Our app is working in 2.0.4 release. After upgrade to 2.2.2.RELEASE we see integration tests failing. I suspect that there is some misconfiguration, and each integration test simply does not clean after itself or there is extra initialization which weren't here before. I really do not know how to fix it properly. To be specific. Each test works when invoked separately. When executed all of them we do see errors like: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing

IntegrationTest isolation fails in springboot 2.2.2.RELEASE (Error dopping tables after each SpringBootTest)

倾然丶 夕夏残阳落幕 提交于 2020-01-15 05:41:02
问题 Our app is working in 2.0.4 release. After upgrade to 2.2.2.RELEASE we see integration tests failing. I suspect that there is some misconfiguration, and each integration test simply does not clean after itself or there is extra initialization which weren't here before. I really do not know how to fix it properly. To be specific. Each test works when invoked separately. When executed all of them we do see errors like: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing

How to check if a h2 database needs to be upgraded?

爷,独闯天下 提交于 2020-01-15 02:38:17
问题 On H2 download site there is a Database Upgrade Helper File for upgrading from 1.1 to a newer version. I wonder if there a nice and clean way of checking if a database needs to upgraded. What I was doing so far was opening a connection to an old db with a new driver, catching the exception and then doing the migration. I would like to do the check in Java if possible. 回答1: If you have the Database Upgrade Helper File in your classpath, and the database was created with H2 version 1.1, then

How do I override the cascade delete for a relation in Grails GORM?

我怕爱的太早我们不能终老 提交于 2020-01-14 19:38:27
问题 I'm having some problems with the GORM part of Grails. I am using Grails 1.3.4, together with H2. In the database I have two tables template and report . On the GORM-level I have the two Domain classes Template and Report ; class Template { static hasMany = [reports: Report] ... } and class Report { static belongsTo = [template: Template] ... } Default behaviour seems to be that when a Template is deleted, the deletion will be cascaded so that all Report s that it has will be deleted as well.

H2 “OTHER” data type throws Exception when storing String or Boolean

…衆ロ難τιáo~ 提交于 2020-01-14 03:42:05
问题 I understand that the OTHER data type can store any Serializable object. However when I try to store an instance of String or Boolean it fails with an exception. Is this a misunderstanding on my part, or a bug in H2? Here's repro code. import org.h2.jdbc.JdbcSQLException; import java.io.Serializable; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class ScratchSpace { public static void main(String[] args)

Flyway migrations not persistent in H2 embedded database

99封情书 提交于 2020-01-13 10:18:27
问题 I'm actually writing a small web application with spring boot and wanted to use a (embedded) H2 database together with Spring Data JPA and Flyway for database migration. This is my application.properties: spring.datasource.url=jdbc:h2:~/database;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1; spring.datasource.username=admin spring.datasource.password=admin spring.datasource.driver-class-name=org.h2.Driver In the main() method of my @SpringBootApplication class I do the following: ResourceBundle

Spring Boot in memory database H2 doesn't load data from file on initialization

♀尐吖头ヾ 提交于 2020-01-13 09:34:13
问题 I have an issue with loading data into an in-memory database on application initialization. I have created schema.sql and data.sql files containing table structure and initial data. schema.sql : CREATE TABLE users ( id INT PRIMARY KEY, username VARCHAR(64) NOT NULL, password VARCHAR(64) ); and data.sql : INSERT INTO users (id, username, password) VALUES (1, 'usr1', 'bigSecret'), (2, 'usr2', 'topSecret'); I am using JpaRepository for working with data layer: public interface UserRepository

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

匆匆过客 提交于 2020-01-13 07:44:39
问题 I have an entity: @Entity public class Student { @GeneratedValue(strategy = GenerationType.AUTO) @Id private long id; @OneToMany private Set<Course> courses; } When I try to persist the first entity of this type it works fine, but then when I try to save a new Student with the same course as the already stored entity it fails. Here is the error: insert into student_courses (student, courses) values (?, ?) [23505-172]]; nested exception is org.hibernate.exception.ConstraintViolationException:

How to write sql query whose conditions are optional?

浪子不回头ぞ 提交于 2020-01-12 09:14:28
问题 I have to write a query where conditional parameters are not known because they are set dynamically in jdbc. And those conditions should be optional. I use h2 database. The query is : select e.event_id,a.attempt_id,a.preferred,a.duration,a.location from event e,attempt a where e.user_label=? and e.start_time=? and e.end_time=? and e.duration_min=? and e.duration_max=? and e.event_id=a.event_id But how to make these conditions optional except using OR because params are not known? Thanks! 回答1:

SQL “SCRIPT” command to backup h2 database

自作多情 提交于 2020-01-11 07:01:07
问题 I have an application with h2 database. I want to create .sql file using SCRIPT command in Java. If I am executing it using Prepared Statement: PreparedStatement stmt = con.prepareStatement("SCRIPT"); ResultSet rs = stmt.executeQuery(); Then how can I able to get whole result in single String. I am new to Java so unable to find the way out to get result of that query because it doesn't contains column names in it. Then I will write it in file using InputStream . 回答1: If you want to backup