title: JPA Inheritance with JOINED strategy
body: <p>I've seen many posts about inheritance but nothing match my problem.</p>
  
  <p>I try to build a correct objects model:</p>
  
  <p>The root class</p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.JOINED)
  public abstract class Identity {
  
      @Id
      @GeneratedValue
      public long id;
  
  }
  </code></pre>
  
  <p>An intermediate class</p>
  
  <pre><code>@Entity
  public class Group extends Identity {
  
      @ManyToMany
      public Collection&lt;Identity&gt; identities = new HashSet&lt;&gt;();
  
  }
  </code></pre>
  
  <p>Two other class, one that inherits from <code>Group</code> and the other from <code>Identity</code></p>
  
  <pre><code>@Entity
  public class Abonne extends Group {}
  
  @Entity
  public class User extends Identity {}
  </code></pre>
  
  <p>I use springboot 1.5.2 and a mysql database. I allready have some application with the same configuration, but it's the first time I try such an inheritance model.</p>
  
  <p>When I run springboot, it launches exceptions at tables creation time:</p>
  
  <pre><code>org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) on project mova.pcp: An exception occurred while running. null
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
      at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
      at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
      at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
      at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
  Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occurred while running. null
      at org.springframework.boot.maven.AbstractRunMojo$IsolatedThreadGroup.rethrowUncaughtException(AbstractRunMojo.java:495)
      at org.springframework.boot.maven.RunMojo.runWithMavenJvm(RunMojo.java:95)
      at org.springframework.boot.maven.AbstractRunMojo.run(AbstractRunMojo.java:249)
      at org.springframework.boot.maven.AbstractRunMojo.execute(AbstractRunMojo.java:181)
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
      ... 21 more
  Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:527)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
      at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
      at alfresco.less.Config.main(Config.java:16)
      ... 6 more
  Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] 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.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
      ... 21 more
  Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [create table group (id bigint not null, primary key (id))]
      at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:59)
      at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:431)
      at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:420)
      at org.hibernate.tool.schema.internal.SchemaMigratorImpl.createTable(SchemaMigratorImpl.java:236)
      at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:167)
      at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60)
      at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134)
      at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101)
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:472)
      at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
      ... 27 more
  Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group (id bigint not null, primary key (id))' at line 1
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
      at com.mysql.jdbc.Util.getInstance(Util.java:408)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2497)
      at com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1540)
      at com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2595)
      at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1468)
      at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:56)
      ... 37 more
  </code></pre>
  
  <p>In my database I only see abonne table. I tried without abonne entity (without <code>Entity</code> annotation AND without <code>extends Group</code>) and it still not working. Then it seems that the problem comes from <code>InheritanceType.JOINED</code>. When I start with default inheritance strategy, it works well! But i don't want abonne data in the root table.</p>
  
  <p>Any help?</p>