h2

Hibernate/H2 foreign key throwing org.h2.jdbc.JdbcSQLException

China☆狼群 提交于 2019-12-13 00:08:20
问题 I'm trying to use an H2 db for my unit testing. My actual database is MYSql, so i'm using the MYSQL dialect with H2. The problem appears to happen once the hbm files are read/loaded. The foreign keys/associations go out of whack as H2 or Hibernate try to alter the tables., or so it seems. DB scripts: DROP SCHEMA IF EXISTS `amr` ; CREATE SCHEMA IF NOT EXISTS `amr`; -- ----------------------------------------------------- -- Table `amr`.`classA` -- ----------------------------------------------

What is the sql query for this?

旧时模样 提交于 2019-12-12 21:05:49
问题 Id Project_Id Activity_Time Username 1 100 2008-01-01 11:12:13 A 2 100 2008-01-01 00:00:00 B 3 500 2008-02-01 00:00:00 C 4 300 2008-02-03 00:00:00 D 5 500 2008-03-03 11:11:11 A 6 300 2008-04-04 00:00:00 D 7 500 2008-05-05 00:00:00 C 8 200 2008-06-06 00:00:00 D 9 100 2009-01-01 11:12:13 A 10 300 2010-01-01 01:02:03 A What is the sql query to select Project_Id based on following input : for the given username order by Activity_Time - latest first distinct Project_Id only 10 rows I tried few

H2 Database: Abort Query

守給你的承諾、 提交于 2019-12-12 19:24:31
问题 I have a long running select query on an embedded H2 Database and want to allow the user to cancel the query. How can this be done? I cannot find anything about this. [UPDATE] To be more specific I'm running my query using JPA. How can the query be stopped? 回答1: H2 supports a query timeout setting. You can set this in the database URL as follows: jdbc:h2:~/db/test;query_timeout=10000 . (Maybe this is not the right approach for you, but it might be for others that read this question.) You can

Deleting from two h2 tables with a foreign key

我与影子孤独终老i 提交于 2019-12-12 18:54:04
问题 I have an h2 database with two tables with foreign keys like CREATE TABLE master (masterId INT PRIMARY KEY, slaveId INT); CREATE TABLE slave (slaveId INT PRIMARY KEY, something INT, CONSTRAINT fk FOREIGN KEY (slaveId) REFERENCES master(slaveId)); and need something like DELETE master, slave FROM master m JOIN slave s ON m.slaveId = s.slaveId WHERE something = 43; i.e., delete from both tables (which AFAIK works in MySql). Because of the FOREIGN KEY I can't delete from the master first. When I

Spring test with H2 in memory database truncate all tables

微笑、不失礼 提交于 2019-12-12 18:08:39
问题 I'm a junior CS major student working on an MVC project using spring and I am quite new to spring. I set up an H2 in memory db and wrote 2 sql scripts; one to populate the db and another one to flush it empty. As far as I know, the practical difference between truncate table <table name> and delete from <table name> is truncate table is ddl thus its faster and it also resets the auto incremented columns. The problem is H2's truncate table does not reset auto incremented columns. Could you

How to configure spring-boot project to work with inmemory spatial database for tests?

╄→гoц情女王★ 提交于 2019-12-12 18:07:45
问题 Here is my config now. I want to use hibernate spatial to work with postgis in production. spring: profiles: production datasource: platform: postgres url: jdbc:postgresql://192.168.99.100:5432/dragon username: dragon password: dragon database: driverClassName: org.postgresql.Driver jpa: database: POSTGRESQL database-platform: org.hibernate.spatial.dialect.postgis.PostgisDialect show-sql: true hibernate: ddl-auto: update --- spring: profiles: development datasource: SpatialInMemoryDb jpa:

org.dbunit.dataset.NoSuchTableException, but table exists

和自甴很熟 提交于 2019-12-12 16:22:17
问题 H2 1.4.191. DbUnit 2.5.1. How this can be fixed? Code and results for 3 cases: org.dbunit.dataset.NoSuchTableException: category org.dbunit.dataset.NoSuchTableException: Category org.dbunit.dataset.NoSuchTableException: CATEGORY // <dataset> <Category categoryId="9223372036854775806" categoryName="NAME" categoryParentId="9223372036854775805"/> </dataset> // CREATE TABLE Category ( categoryId INT AUTO_INCREMENT, categoryName VARCHAR NOT NULL, categoryParentId INT NOT NULL, PRIMARY KEY

Grails GORM 'or' not working with associations

元气小坏坏 提交于 2019-12-12 15:58:02
问题 In the following example, I'd expect Product.searchAll to match both additives and products, but it seems to ignore eq('name', taste) . class Additive { String flavor static belongsTo = [product:Product] } class Product { String name static hasMany = [additives:Additive] static constraints = { name nullable:true } static namedQueries = { searchAll { taste -> or { eq('name', taste) additives { eq('flavor', taste) } } } searchAdditives { taste -> additives { eq('flavor', taste) } }

H2 Database - Reorder columns using SQL

送分小仙女□ 提交于 2019-12-12 15:34:24
问题 I have a H2 database with 16 million entries and no primary key. I successfully added an auto-incrementing primary key using the following statements: ALTER TABLE PUBLIC.ADDRESSES ADD ID BIGINT AUTO_INCREMENT; ALTER TABLE PUBLIC.ADDRESSES ADD PRIMARY KEY (ID) Now the problem is, that the column order is STREET, HOUSENUMBER, ..., ID , but I would like ID to be the first column of the table. It looks like there is a corresponding ALTER TABLE statement MySQL (see here), but I'm unable to adapt

Playframework evolutions files compatible with both postgres and h2

試著忘記壹切 提交于 2019-12-12 15:21:03
问题 I've been developing a web site with the Play framework (scala) using H2 as a backend. Testing is nicely integrated, especially with the ability to run tests against an in-memory H2 db. Now I'd like to move my datastore over to Postgres for various convenience reasons. This leaves me with a problem: How to continue to test and retain the simplicity of a fresh db for each test run? I see on the net that some people manage to run live against postgres and test against H2. However the two are