I have a Spring Boot project using Spring Data JPA, with the system property 'spring.jpa.hibernate.ddl-auto=validate'. I refactored some entities to extend a base class annotated with @MappedSuperclass. The application fails to startup with the following error looking for a column on this new base class as if it's an entity:
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [cde] in table [assignments]
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:85) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:475) ~[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]
... 31 common frames omitted
The base class:
Code:
@MappedSuperclass
public abstract class Assignment implements Serializable {
private static final long serialVersionUID = 8822678799185722637L;
@Column
private String cde;
// other common fields, getters/setters, etc.
}
One of the subclasses:
Code:
@Entity
@Table(schema = "TELCOM", name = "VW_ASSIGNMENTS")
public class TelecomAssignmentView extends Assignment implements Serializable {
private static final long serialVersionUID = -8662949007998935627L;
@Column(name = "ACCOUNTNUMBER", insertable = false, updatable = false)
private String accountNumber;
// other fields, getters/setters, etc.
}
Of course I can workaround this if I set the validation property to 'none', but why would Hibernate think a class annotated with @MappedSuperclass is an entity with a backing table in need of validation? Is this a bug? Thanks!