Search code examples
hibernatejpamultiple-inheritance

Schema-validation: missing table with jpa multi level inheritance


I need to have 3 level inheritance with JPA (but just one datatable CELLAR_PER) Here are my Entities

@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class PersistEntity implements Serializable {

     private static final long serialVersionUID = 1L;

     @Id
     @Column(name = "ID", nullable = false)
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     private Integer id;

     ...
}

The second level

@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class PersistEntityPer extends PersistEntity {
   private static final long serialVersionUID = 1L;

   @Temporal(TemporalType.DATE)
   @Column(
      name = "PERIOD_START",
      nullable = false)
   private Date periodStart;

   @Temporal(TemporalType.DATE)
   @Column(
      name = "PERIOD_END",
      nullable = false)
   private Date periodEnd;
 }

And the last level

@Entity
@Table(name = "dbo.CELLAR_PER")
public class CellarPer extends PersistEntityPer {

   private static final long serialVersionUID = 1L;

   @ManyToOne
   @JoinColumn(
      name = "CELLAR_CASE_ID",
      nullable = false)
   private CellarCase cellarCase;
}

My problem is that I get this error when running my tomcat server:

 Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [dbo.CELLAR_PER]
    at org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateTable(AbstractSchemaValidator.java:121)
    at org.hibernate.tool.schema.internal.GroupedSchemaValidatorImpl.validateTables(GroupedSchemaValidatorImpl.java:42)
    at org.hibernate.tool.schema.internal.AbstractSchemaValidator.performValidation(AbstractSchemaValidator.java:89)
    at org.hibernate.tool.schema.internal.AbstractSchemaValidator.doValidation(AbstractSchemaValidator.java:68)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:191)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:889)
    ... 48 common frames omitted

Please, could you help me to fix that error?


Solution

  • Your are right. Here is the solution:

    In my entity declaration, I had this:

    @Table(name = "dbo.CELLAR_PER")
    

    And I just removed the dbo. from the declaration. The solution is:

    @Table(name = "CELLAR_PER")