# Missing table while table exists

**URL:** <https://discourse.hibernate.org/t/missing-table-while-table-exists/224>\
**Category:** Hibernate ORM\
**Created:** [February 10, 2018, 10:00pm UTC](https://discourse.hibernate.org/t/missing-table-while-table-exists/224 "2018-02-10T22:00:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![devil0150](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@devil0150](https://discourse.hibernate.org/u/devil0150)\
**Post date:** [February 10, 2018, 10:00pm UTC](https://discourse.hibernate.org/t/missing-table-while-table-exists/224/1 "2018-02-10T22:00:36Z")

</div>

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

```auto
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:

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

```

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

```auto
<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:

```auto
@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?

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 11, 2018, 8:50am UTC](https://discourse.hibernate.org/t/missing-table-while-table-exists/224/2 "2018-02-11T08:50:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![devil0150](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@devil0150](https://discourse.hibernate.org/u/devil0150)\
**Post date:** [February 11, 2018, 12:46pm UTC](https://discourse.hibernate.org/t/missing-table-while-table-exists/224/4 "2018-02-11T12:46:48Z")

</div>

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

```auto
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](https://drive.google.com/open?id=1vurmtiqvrcV-SIfmZfGHlD1PhdG0c7p6)

ABILITIES is the table I previously renamed to TBL.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 11, 2018, 1:48pm UTC](https://discourse.hibernate.org/t/missing-table-while-table-exists/224/5 "2018-02-11T13:48:42Z")

</div>

> [@devil0150](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![devil0150](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@devil0150](https://discourse.hibernate.org/u/devil0150)\
**Post date:** [February 11, 2018, 2:00pm UTC](https://discourse.hibernate.org/t/missing-table-while-table-exists/224/6 "2018-02-11T14:00:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 11, 2018, 2:10pm UTC](https://discourse.hibernate.org/t/missing-table-while-table-exists/224/7 "2018-02-11T14:10:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![devil0150](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@devil0150](https://discourse.hibernate.org/u/devil0150)\
**Post date:** [February 11, 2018, 5:31pm UTC](https://discourse.hibernate.org/t/missing-table-while-table-exists/224/8 "2018-02-11T17:31:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![devil0150](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@devil0150](https://discourse.hibernate.org/u/devil0150)\
**Post date:** [February 11, 2018, 6:16pm UTC](https://discourse.hibernate.org/t/missing-table-while-table-exists/224/9 "2018-02-11T18:16:48Z")

</div>

I solved it.

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

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 11, 2018, 6:43pm UTC](https://discourse.hibernate.org/t/missing-table-while-table-exists/224/10 "2018-02-11T18:43:21Z")

</div>

I’m glad you fixed it.
