Hibernate 5 with JPA : hibernate access without schema spécified in entity
<p>I have a MAVEN + SPRING + JPA + HIBERNATE + MSYQL application.
I want to upgrade hibernate 4.3.11 to the last version of hibernate v5.</p>
<p>before</p>
<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
    &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
    &lt;version&gt;4.3.11.Final&lt;/version&gt; 
&lt;/dependency&gt;
</code></pre>
<p>after</p>
<pre><code>    &lt;dependency&gt;
    &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
    &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
    &lt;version&gt;5.1.0.Final&lt;/version&gt;
&lt;/dependency&gt;

    
</code></pre>
<p>But when I try to access to a entity which table isn't in default schema, I have a error.
Before the upgrade, it was good.
Access a entity which table is in default schema works with V5 hibernate.</p>
<p>Default schema is &quot;roles&quot; but in all the entity of my application, I explicit the schema in @table JPA Annotation.
Even if schema is &quot;roles&quot;</p>
<p>The Entity :</p>
<pre><code>@Entity
@Table(schema=&quot;modeler&quot;,name=&quot;concept&quot;)

public class Concept {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(unique=true, nullable=false,  updatable = false)
private int idconcept;

@Column(name=&quot;action_date&quot;, nullable=false)
protected LocalDate actionDate;

...

public Concept() {}

...

}
</code></pre>
<p>When I try a read access with this entity, I have the Java error:</p>
<blockquote>
<p>Exception: org.hibernate.exception.SQLGrammarException: could not extract ResultSet</p>
</blockquote>
<pre><code>In the stack, the cause is: 
         &quot;errorCode&quot;: 1146,
        &quot;nextException&quot;: null,
        &quot;sqlstate&quot;: &quot;42S02&quot;,
        &quot;localizedMessage&quot;: &quot;Table 'roles.concept' doesn't exist&quot;,
        &quot;message&quot;: &quot;Table 'roles.concept' doesn't exist&quot;,
        &quot;suppressed&quot;: []
</code></pre>
<p>in the log of hibernate, I saw the SQL order doesn't contain the schema.</p>
<pre><code>Sql order with hibernate 5 

    select concept0_.idconcept as idconcep1_0_, concept0_.action_date a saction_d2_0_, ..., from concept concept0_

Sql order before with hibernate 4.3.11

    select concept0_.idconcept as idconcep1_0_, concept0_.action_date a saction_d2_0_, ..., from modeler.concept concept0_
</code></pre>
<p>When I try to persist the entity, I have an error in the same theme but on the hibernate_sequence table</p>
<blockquote>
<p>Exception: org.hibernate.exception.SQLGrammarException: error performing isolated work</p>
</blockquote>
<pre><code>In the stack, the cause is 
        &quot;errorCode&quot;: 1146,
         &quot;nextException&quot;: null,
         &quot;sqlstate&quot;: &quot;42S02&quot;,
        &quot;localizedMessage&quot;: &quot;Table 'roles.hibernate_sequence' doesn't exist&quot;,
        &quot;message&quot;: &quot;Table 'roles.hibernate_sequence' doesn't exist&quot;,
        &quot;suppressed&quot;: []
</code></pre>
<p>in the log of hibernate, the SQL order doesn't contain the schema.</p>
<pre><code>     select next_val as id_val from hibernate_sequence for update

--&gt; but, it's seems that it's the same schema problem as in read access.
</code></pre>
<p>So I tried to find a solution before my question.
I found on hibernate site that version v5.0.8 was stable and tried it.
I had the same problem with it.</p>
<p>So I read the evolutions of the V5.0.8.
The only change which have focused my attention was : Naming strategies
I modified my xml spring configuration with some solution find on the web .
But, it doesn't work.</p>
<p>Extract of my <code>xml spring</code> configuration</p>
<pre><code>&lt;tx:annotation-driven transaction-manager=&quot;transactionManager&quot; /&gt;
&lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;&gt;
    &lt;property name=&quot;entityManagerFactory&quot; ref=&quot;entityManagerFactory&quot; /&gt;
&lt;/bean&gt;


&lt;bean id=&quot;entityManagerFactory&quot;
    class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&gt;
    &lt;property name=&quot;persistenceXmlLocation&quot; value=&quot;classpath:config/persistence.xml&quot; /&gt;
    &lt;property name=&quot;persistenceUnitName&quot; value=&quot;demoRestPersistence&quot; /&gt;
    &lt;property name=&quot;dataSource&quot; ref=&quot;restDemoDS&quot; /&gt;
    &lt;property name=&quot;jpaVendorAdapter&quot;&gt;
        &lt;bean class=&quot;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&quot;&gt;
        &lt;/bean&gt;
    &lt;/property&gt;
    
     &lt;property name=&quot;jpaPropertyMap&quot;&gt;
        &lt;map&gt;
            &lt;entry key=&quot;hibernate.show_sql&quot; value=&quot;true&quot; /&gt;
            &lt;entry key=&quot;hibernate.dialect&quot; value=&quot;org.hibernate.dialect.MySQLDialect&quot; /&gt;
            &lt;entry key=&quot;hibernate.implicit_naming_strategy&quot; value=&quot;org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl&quot; /&gt;
        &lt;/map&gt;
    &lt;/property&gt;
    
&lt;/bean&gt;

&lt;bean id=&quot;restDemoDS&quot;
    class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;
    scope=&quot;singleton&quot;&gt;
    &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot; /&gt;
    &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:3306/roles&quot; /&gt;
    &lt;property name=&quot;username&quot; value=&quot;***&quot; /&gt;
    &lt;property name=&quot;password&quot; value=&quot;******&quot; /&gt;
&lt;/bean&gt;
</code></pre>