Home Table not found with H2
Reply: 0

Table not found with H2

user2089
1#
user2089 Published in August 14, 2018, 8:27 am

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:

@Entity
@Table(name = "MY_TABLE")
public class MyTable {
    // ...
}

This is how I call JPA (this causes the exception):

@PersistenceContext
private EntityManager entityManager;

// ...

entityManager.find(MyTable.class, 1);

My persistence.xml is:

<persistence-unit name="myapp" transaction-type="JTA">
    <jta-data-source>java:jboss/datasources/myappDS</jta-data-source>
</persistence-unit>

And the standalone.xml in my WildFly:

<datasource jndi-name="java:jboss/datasources/myappDS" pool-name="myappDS" enabled="true" use-java-context="true">
    <connection-url>jdbc:h2:~/myapp;SCHEMA=PUBLIC</connection-url>
    <driver>h2</driver>
</datasource>
<drivers>
    <driver name="h2" module="com.h2database.h2">
        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
    </driver>
</drivers>

Everything looks good so why the exception? Do I need to flush something? Or set schema somewhere?

If I configure another datasource (having the same DB structure) in WildFly (for example Postgres), everything works fine. That would mean that the datasource configuration is the place causing the error.

(Yes, I am totally sure the DB is not empty and the connection URL is correct as I have tried it from an SQL client.)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.288596 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO