title: Hibernate - Table or view doesnt not exist error
body: <p>I am trying to save an object in database using hibernate. When I run the code for the first time with a new table name it throws below error, but when I run it second time it works perfectly fine- </p>
  
  <pre><code>    INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@61ce23ac] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
  Sep 01, 2016 3:51:18 AM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
  WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
  org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
      at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:62)
      at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:374)
      at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359)
      at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:241)
      at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154)
      at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126)
      at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112)
      at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:137)
      at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:65)
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:307)
      at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:490)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
      at org.sf.main.SessionFactoryBuilder.getSessionFactory(SessionFactoryBuilder.java:26)
      at org.sf.main.SessionFactoryBuilder.main(SessionFactoryBuilder.java:36)
  Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
  
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
      at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
      at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
      at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
      at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
      at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:195)
      at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:1036)
      at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
      at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1916)
      at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1878)
      at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:318)
      at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:49)
      ... 13 more
  </code></pre>
  
  <p>Here is my code-</p>
  
  <pre><code>    public static SessionFactory getSessionFactory() {
              Configuration configuration = new Configuration();
  
              configuration.setProperty("hibernate.hbm2ddl.auto", "create");
              configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
              configuration.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
              configuration.setProperty("hibernate.connection.url", "jdbc:oracle:thin:@somehost:1521:orcl");
              configuration.setProperty("hibernate.connection.username", "username");
              configuration.setProperty("hibernate.connection.password", "password");
              configuration.setProperty("show_sql", "true");
              configuration.setProperty("hibernate.default_schema", "somechema");
              configuration.setPhysicalNamingStrategy(new HelloWorldNamingStrategy());
              configuration.addAnnotatedClass(Census2010.class);
  
              StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
              SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build()); 
  
              return sessionFactory;
          }
  
          public static void main (String[] args) {
              Census2010 obj = new Census2010();
              obj.setData(100000L);
              obj.setVariable("Population");
  
              SessionFactory factory = getSessionFactory();
              Session session = factory.openSession();
              session.beginTransaction();
              session.save(obj);
              session.getTransaction().commit();
  
              factory.close();
  
          }
  </code></pre>
  
  <p>Here is my Entity class-</p>
  
  <pre><code>    import javax.persistence.Column;
  
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.Table;
  
      @Entity
      @Table
      public class Census2010 {
          @Id
          @Column(name="VARIABLE")
          private String variable;
  
          @Column(name="DATA")
          private long data;
  
          public String getVariable() {
              return variable;
          }
  
          public void setVariable(String variable) {
              this.variable = variable;
          }
  
          public long getData() {
              return data;
          }
  
          public void setData(long data) {
              this.data = data;
          }
      }
  </code></pre>
  
  <p>Here is the NamingStrategy class-</p>
  
  <pre><code>import org.hibernate.boot.model.naming.Identifier;
  import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
  import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
  
  public class HelloWorldNamingStrategy extends PhysicalNamingStrategyStandardImpl {
  
      private static final long serialVersionUID = 1L;
  
      private static final String tableName = "A_12345_P";
  
      @Override
       public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
           return new Identifier(tableName, true);
       }
  }
  </code></pre>
  
  <p>Any help is appreciated.</p>