title: Hibernate 4 -> 5 migration: NamingStrategy changes, Tables not found
body: <h1>What i want to do</h1>
  
  <p>I'm trying to migrate from WildFly 8.2.0 to WildFly 10.0.0 which means that i have (and want) to migrate from Hibernate 4.3 to Hibernate 5.0.</p>
  
  <h1>Setup</h1>
  
  <pre><code>Java 8u40 
  Spring 4.1.9 
  SQL Server 2012
  Wildfly 8.2.0 -&gt; Wildfly 10.0.0 
  Hibernate 4.3.6 -&gt; Hibernate 5.0.7
  </code></pre>
  
  <p>I have read the <a href="https://github.com/hibernate/hibernate-orm/blob/5.0/migration-guide.adoc" rel="nofollow noreferrer">migration guide</a> and i'm hit by the <strong>Naming Strategy</strong> changes. I <a href="https://stackoverflow.com/questions/33111949/hibernate-5-implicitnamingstrategy">have</a> <a href="https://stackoverflow.com/questions/32864327/migrating-to-hibernate-5">read</a> <a href="https://stackoverflow.com/questions/32165694/spring-hibernate-5-naming-strategy-configuration">many</a> <a href="https://stackoverflow.com/questions/32437202/improvednamingstrategy-no-longer-working-in-hibernate-5">questions</a> about this on SO, but mine seems a bit different. Hibernate complains that tables are not found:</p>
  
  <pre><code>INFO [o.h.Version] HHH000412: Hibernate Core {5.0.7.Final}
  INFO [o.h.cfg.Environment] HHH000206: hibernate.properties not found
  INFO [o.h.cfg.Environment] HHH000021: Bytecode provider name : javassist
  INFO [o.h.annotations.common.Version] HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
  INFO [o.h.dialect.Dialect] HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect
  INFO [o.h.envers.boot.internal.EnversServiceImpl] Envers integration enabled? : true
  INFO [o.h.validator.internal.util.Version] HV000001: Hibernate Validator 5.2.3.Final
  INFO [o.h.tool.hbm2ddl.SchemaValidator] HHH000229: Running schema validator
  INFO [o.h.t.s.e.i.InformationExtractorJdbcDatabaseMetaDataImpl] HHH000262: Table not found: SEC_AUTHORIZATION_RULES
  INFO [o.h.t.s.e.i.InformationExtractorJdbcDatabaseMetaDataImpl] HHH000262: Table not found: SEC_USER
  More tables not found ...
  INFO [o.h.hql.internal.QueryTranslatorFactoryInitiator] (ServerService Thread Pool -- 62) HHH000397: Using ASTQueryTranslatorFactory
  </code></pre>
  
  <p>When i switched to DEBUG logging i saw for example that he is binding the entity to the correct DB table:</p>
  
  <pre><code>DEBUG [o.h.c.a.EntityBinder] Bind entity com.company.user.User on table SEC_USER
  DEBUG [o.h.c.Ejb3Column] Binding column: Ejb3Column{table=org.hibernate.mapping.Table(SEC_USER), mappingColumn=ID, insertable=true, updatable=true, unique=false}
  </code></pre>
  
  <p>What is odd to me is that the app works. After this <code>Table not found</code>s it does not complain that schema is not right. The app works. Selecting, inserting, updating data works. </p>
  
  <p>I have hibernate configured through it's spring-orm abstraction:</p>
  
  <pre><code>@Bean(name = "myEmf")
  @DependsOn({"dataSource", "flyway"})
  public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
      LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
      em.setDataSource(dataSource());
      em.setPackagesToScan(new String[]{"com.company.**.*"});
      em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
      em.setJpaProperties(additionalProperties());
      return em;
  }
  
  private Properties additionalProperties() {
    Properties propFile = propertiesFile();
    properties.setProperty("hibernate.hbm2ddl.auto", "validate");
    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServer2012Dialect");
    properties.setProperty("hibernate.show_sql", "false");
    properties.setProperty("hibernate.format_sql", "true");
    properties.setProperty("hibernate.id.new_generator_mappings", "false");
    properties.setProperty("hibernate.use_sql_comments", "false");
    properties.setProperty("hibernate.implicit_naming_strategy", "legacy-jpa");
    return properties;
  }
  </code></pre>
  
  <p>In this correspoding entity i have table names and column names named explicitly:</p>
  
  <pre><code>@Entity
  @Table(name = "SEC_USER")
  public class User extends BaseEntity {
  
     @Column(name = "LOGIN", nullable = false, unique = true)
     private String login;
  </code></pre>
  
  <h1>Questions</h1>
  
  <ul>
  <li>How to make this table not found log messages disappear?</li>
  <li>Why they are appearing if i have table names explicitly named?</li>
  <li>Why is he not complainging about column names?</li>
  <li>Why is he <strong>seemingly working correct</strong>?</li>
  </ul>
  
  <h1>What i have tried</h1>
  
  <ul>
  <li>Upgrading Spring 4.1.9 to 4.2.5 which <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/new-in-4.2.html#_data_access_improvements" rel="nofollow noreferrer">says he has support for Hibernate 5</a></li>
  <li>Set <em>hibernate.implicit_naming_strategy</em> to <strong>legacy-jpa</strong> according to <a href="http://in.relation.to/2015/08/05/hibernate-orm-500-cr4-release/" rel="nofollow noreferrer">this</a></li>
  <li><p>Set manually the default schema and assigned the role db_owner. Note i never had to do this before with hibernate 4.
  <a href="https://i.stack.imgur.com/nNSA2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nNSA2.jpg" alt="enter image description here"></a> </p></li>
  <li><p>I have debugged hibernate a bit and what i found in the <a href="https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java" rel="nofollow noreferrer">InformationExtractorJdbcDatabaseMetaDataImpl.java</a> that hibernate does not see the catalog (whatever this is) and schema. At leat i think he should see the schema. See screenshot below: catalog and schema are null.
  <a href="https://i.stack.imgur.com/cxTWt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cxTWt.jpg" alt="enter image description here"></a></p></li>
  </ul>