pecka
1#
pecka Published in 2018-01-10 20:06:56Z
 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:  java:jboss/datasources/myappDS  And the standalone.xml in my WildFly:  jdbc:h2:~/myapp;SCHEMA=PUBLIC h2 org.h2.jdbcx.JdbcDataSource  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.)
Per Huss
2#
Per Huss Reply to 2018-01-11 10:25:59Z
 Are you running the application as a different user than you are testing to connect with? In that case the the ~ in the connection path will resolve to different home folders, and thus different databases. Otherwise I would suggest connecting with the Shell in the h2 jar file and run show tables to verify that the table exists and with the correct casing. Start the shell by running: java -cp h2*.jar org.h2.tools.Shell 
Georg Henkel
3#
Georg Henkel Reply to 2018-01-11 10:37:08Z
 Where do you store your script for the table creation? Is it in classpath of the application? In my test setup I let hibernate generate the tables on startup (and dropping it on shutdown) and using an import.sql script for the test-data generation, which is in the folder src/main/resources.  java:jboss/datasources/myappDS 
 You need to login account before you can post.
Processed in 0.349845 second(s) , Gzip On .