title: InheritanceType.JOINED strategy not working in with Spring Boot
body: <p>I have problem implementing InheritanceType.JOINED strategy with hibernate. </p>
  
  <p>All the time I got this kind of exception:</p>
  
  <pre><code>Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
      at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      ... 16 common frames omitted
  Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.JoinedSubclassEntityPersister
      at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:112) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:348) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
      ... 22 common frames omitted
  Caused by: org.hibernate.AssertionFailure: Table school_service.abstract_person not found
      at org.hibernate.persister.entity.AbstractEntityPersister.getTableId(AbstractEntityPersister.java:5118) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.persister.entity.JoinedSubclassEntityPersister.&lt;init&gt;(JoinedSubclassEntityPersister.java:433) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_51]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_51]
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_51]
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_51]
      at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      ... 26 common frames omitted
  </code></pre>
  
  <p>I created a Spring Boot / Gradle project to replicate the bug here: <a href="https://github.com/tamershahin/JoinTableTest" rel="nofollow noreferrer">https://github.com/tamershahin/JoinTableTest</a></p>
  
  <p>this is the Main Class:</p>
  
  <pre><code> @Entity
  @Inheritance(strategy = InheritanceType.JOINED)
  @DiscriminatorColumn(name = "person_type")
  @Table(name = "abstract_person",schema = "school_service")
  @AllArgsConstructor
  @NoArgsConstructor
  public class Person {
  
      @Id
      @GeneratedValue()
      @Column(name="person_id")
      private Long id;
  
      @Column(nullable = false, length = 125, name="name")
      @Getter
      @Setter
      String name;
  
     @Column(name = "person_type", nullable = false)
      @Getter@Setter
      String personType;
  
  }
  </code></pre>
  
  <p>and this the one extending it:</p>
  
  <pre><code>@Entity
  @DiscriminatorValue("student")
  @Table(name = "student_detail",schema = "school_service")
  @PrimaryKeyJoinColumn(name = "student_id", referencedColumnName = "person_id")
  @Builder(toBuilder = true)
  @NoArgsConstructor
  @AllArgsConstructor
  public class Student extends Person {
  
      @Column(length = 32, nullable = false)
      @Getter
      @Setter
      String email;
  
      @Column(length = 32, nullable = false)
      @Getter
      @Setter
      String className;
  }
  </code></pre>
  
  <p>essentially I'm following the JPA guidelines, and in fact if I switch to InheritanceType.TABLE_PER_CLASS strategy everything works, but that implementation is not what I need.</p>
  
  <p>I debugged a bit the class: .../hibernate-core-5.0.11.Final-sources.jar!/org/hibernate/persister/entity/AbstractEntityPersister.java</p>
  
  <p>and I noticed that this bit of code: </p>
  
  <pre><code>for ( int j = 0; j &lt; tables.length; j++ ) {
              if ( tableName.equalsIgnoreCase( tables[j] ) ) {
                  return j;
              }
          }
  </code></pre>
  
  <p>never returns the right table because tableName always contains the schema and tables don't.. that's why it's not able to find the table.</p>
  
  <p>Is it me misconfiguring / misusing something or is this a proper bug?</p>
  
  <p>Thanks folks.</p>
  
  <p>T</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I'm using this property:</p>
  
  <p>spring.jpa.hibernate.ddl-auto=create-drop</p>
  
  <p>so the DB should be generated by Hibernate on his needing, but everything crashes before it.</p>
  
  <p>I also tried to create the class manually as explained here:
  <a href="http://www.javaroots.com/2013/07/hibernate-inheritance-joined-strategy.html" rel="nofollow noreferrer">http://www.javaroots.com/2013/07/hibernate-inheritance-joined-strategy.html</a></p>
  
  <p>but no success.</p>
  
  <p>UPDATE:
  After @crafarlo comment I start playing with application.properties and I found that removing this config:</p>
  
  <p>spring.jpa.properties.hibernate.default_schema</p>
  
  <p>will do the trick. </p>
  
  <p>This is my full config:</p>
  
  <pre><code>urlwithoutschema=jdbc:mysql://localhost:3306/
  spring.datasource.url=${urlwithoutschema}${spring.datasource.schema}
  spring.datasource.username=school
  spring.datasource.password=school
  spring.datasource.schema=school_service
  spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  spring.jpa.hibernate.ddl-auto=none
  spring.jpa.show-sql=true
  #spring.jpa.properties.hibernate.default_schema=${spring.datasource.schema}
  </code></pre>
  
  <p>I don't see why this will affect the mapping class-tables, but it does.. any clue?</p>