h2 database in postgres emulation mode can't find table named user

Viewed 795

I suspect this is a bug in the h2 postgres emulation mode, but I am running into the following issue: I have a table named "user" in my database. I am accessing the database using Hibernate. Since "user" is a reserved keyword in Postgres, the annotation looks like this, with tick marks to escape the name:

@Entity @Table(name = "`user`")
public class User {
...
}

I am using Liquibase to create my table and it looks like this:

<changeSet id="3" author="Peter">
    <createTable tableName="user">
        <column name="id" type="char(8)">
            <constraints primaryKey="true" nullable="false" unique="true"/>
        </column>
        <column name="active" type="boolean">
            <constraints nullable="false"/>
        </column>
    </createTable>
</changeSet>

When I make a query with Hibernate running against a real Postgres, this works fine. When I use H2, however, I get the following error:

Hibernate: insert into "user" (active, id) values (?, ?) WARN [2017-10-03 13:54:52,105] org.hibernate.engine.jdbc.spi.SqlExceptionHelper: SQL Error: 42102, SQLState: 42S02 ERROR [2017-10-03 13:54:52,108] org.hibernate.engine.jdbc.spi.SqlExceptionHelper: Table "user" not found; SQL statement: insert into "user" (active, id) values (?, ?) [42102-196] ERROR [2017-10-03 13:54:52,111] org.hibernate.internal.ExceptionMapperStandardImpl: HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not prepare statement]

My JDBC connection string for H2 is the following:

jdbc:h2:mem:testdb;MODE=PostgreSQL;DB_CLOSE_DELAY=-1

When I remove the tick marks escaping "user", it works again, but then it doesn't work in real Postgres.

Is there any way I can fix this?

Thanks.

0 Answers
Related