Missing table while table exists

I am trying to setup JPA with hibernate, and using JBoss to deploy. I am getting this error:

org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [TBL]
	at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:67)
	at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50)
	at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:473)
	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
	... 9 more

But I do have a table called TBL in the database, created with this code:

create table TBL ( id number(10) not null primary key );

I’m using oracle, and this is my persistence.xml file:

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
  version="2.1">

  <persistence-unit name="unit1" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:usr/pass@//localhost:1521/XE" />
      <property name="javax.persistence.jdbc.user" value="usr" />
      <property name="javax.persistence.jdbc.password" value="pass" />
      <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />

      <property name="hibernate.show_sql" value="true" />
      <property name="hibernate.format_sql" value="true" />
      <property name="hibernate.hbm2ddl.auto" value="validate" />

      <!-- Configuring Connection Pool -->
      <property name="hibernate.c3p0.min_size" value="5" />
      <property name="hibernate.c3p0.max_size" value="10" />
      <property name="hibernate.c3p0.timeout" value="500" />
      <property name="hibernate.c3p0.max_statements" value="30" />
      <property name="hibernate.c3p0.idle_test_period" value="2000" />
    </properties>
  </persistence-unit>
</persistence>

I do have ojdbc6, version 11.2.0.3 in the pom.xml file.

This is the java class for that table:

@Entity
@Table(name = "TBL")
public class Tbl implements Serializable {
    public enum EnumName { /*...*/ }

    // private and public static final variables

    @Id
    private Long id;

    public Tbl() {}

    // some getters
}

If I connect to the database from command line, I can do a select on the table.

I tried changing from validate to update or create.

  • With update I still get the “Table not found: TBL” message every time I restart the server, so I’m guessing whatever hibernate is doing is not permanent.
  • With create, I see the sql code dropping and creating the tables. Then I switched back to validate and restarted to make sure it worked. I still got the missing table exception.

What am I missing?

Just switch to DEBUG or TRACE for the org.hibernate log appender and then attach the Stacktrace so we know for sure what happens.

The stack trace of the error message was the same even on TRACE level. This is all of it:

org.jboss.msc.service.StartException in service jboss.persistenceunit."sockets.war#unit1": javax.persistence.PersistenceException: [PersistenceUnit: unit1] Unable to build Hibernate SessionFactory
	at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
	at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
	at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)
	at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
	at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: unit1] Unable to build Hibernate SessionFactory
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882)
	at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
	at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
	... 7 more
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [ABILITIES]
	at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:67)
	at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50)
	at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:473)
	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
	... 9 more

Here is the full server log:
https://drive.google.com/open?id=1vurmtiqvrcV-SIfmZfGHlD1PhdG0c7p6

ABILITIES is the table I previously renamed to TBL.

Then it means, you deployed a WAR or EAR which contains the old entities pointing to ABILITIES.

Just add a breakpoint in SchemaValidatorImpl.doValidation and see eactly what happens.

I meant I renamed it in the post, not in the code. As for the breakpoint, I’m starting the server from the commandline, not an IDE, so I don’t think I can create breakpoints.

Yes, you can. Just check the JBoss bat or sh file for more details. Search for debug and you will see what environment variable to set and the port used for remote debuging.

I put a breakpoint. metadata.database.jdbcEnvironment.currentSchema is null.
Does that mean it’s not connecting to the database? I can connect from command line so I don’t think it’s the firewall.

I solved it.

Apparently I had to configure the database as a datasource in Jboss, not just in the persistence.xml file.

I’m glad you fixed it.