apache / apache/grails-core

Standalone GORM + H2 in memory is not creating tables

Open
#14,435 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-hibernate5
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

I created a sample minimalist project here.
https://github.com/aibolit/StandaloneGORM-Groovy3/tree/groovy2

To Run: `./gradlew run`

There is one domain class and some minimal setup for an H2 in-memory database.

I am seeing
```
[main] INFO org.hibernate.Version - HHH000412: Hibernate Core {5.4.10.Final}
[main] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.18.Final
[main] INFO org.hibernate.validator.internal.engine.ConfigurationImpl - HV000002: Ignoring XML configuration.
[main] INFO org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
[main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.H2Dialect

Hibernate: drop table person if exists
Hibernate: create table person (id bigint generated by default as identity, version bigint not null, first_name varchar(255) not null, last_name varchar(255) not null, primary key (id))

[main] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 42102, SQLState: 42S02
[main] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Table "PERSON" not found; SQL statement:
```

This is weird because I can clearly see the `create table` statement run without error. My guess is that this is somehow running on the wrong schema (If I run SQL to manually using `new Sql(datastore.dataSource)` to create the table, it still doesn't work with the GORM entities but does work with more manual SQL create/select).

> Note - This same code works with the [comdb2](https://github.com/bloomberg/comdb2) database. I am trying to create a minimal in memory example.

Contributor guide

Open the contributing guide

Research direction

Start with the linked StandaloneGORM-Groovy3 sample and run ./gradlew run to reproduce the H2 in-memory failure. Inspect the minimal domain class, GORM setup, and generated SQL around the table-creation and subsequent entity query; done means the GORM entities can use the created person table without a table-not-found error.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.