模式验证:缺少具有jpa多级继承的表

时间:2017-10-26 06:24:35

标签: hibernate jpa multiple-inheritance

我需要使用JPA进行3级继承(但只需要一个数据表CELLAR_PER) 这是我的实体

@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;

     ...
}

第二级

@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;
 }

最后一级

@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;
}

我的问题是运行我的tomcat服务器时出现此错误:

 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

拜托,你能帮我修一下这个错误吗?

1 个答案:

答案 0 :(得分:0)

你是对的。这是解决方案:

在我的实体声明中,我有这个:

@Table(name = "dbo.CELLAR_PER")

我刚刚从声明中删除了dbo.。解决方案是:

@Table(name = "CELLAR_PER")