I'm setting up a spring boot (2.1.2-RELEASE) application initializing a database context. The database context is already configured in a different spring application (3.2.18-RELEASE) and running properly. When starting the application I get the following error message:
org.hibernate.MappingException: property [identifiers] not found on entity [my.package.collection.CollectionIdentifier]
The initialization of the database is spring boot standard by providing the properties
spring.datasource.* and spring.jpa.*
As visible in the code below the "identifiers" property is not available in the CollectionIdentifier entity. However it is present in the CollectionMaster entity. And that's the way it should be
CollectionMaster entity containing the "identifiers" property
@Entity
@Audited
public class CollectionMaster extends AbstractPersistentObject implements Identifiable<CollectionIdentifier> {
private static final String COLLECTION_ID = "collection_id";
@OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL, orphanRemoval=true)
@JoinColumn(name=COLLECTION_ID)
@Valid
private Set<CollectionIdentifier> identifiers;
public final Set<CollectionIdentifier> getIdentifiers() {
if(identifiers == null) {
identifiers = new HashSet<>();
}
return identifiers;
}
Identifiable interface
public interface Identifiable<R extends AbstractIdentifier> {
Set<R> getIdentifiers();
CollectionIdentifier entity
@Entity
@Audited
public class CollectionIdentifier extends AbstractIdentifier implements Comparable<CollectionIdentifier> {
@Column(length=SIZE_3)
private String type;
@Column(length=SIZE_3)
private String identifierType;
@NotNull
@Column(nullable=false, length=SIZE_65)
private String value;
AbstractIdentifier mapped superclass
@MappedSuperclass
public abstract class AbstractIdentifier extends AbstractPersistentObject {
@Column(length=SIZE_50)
private String typeName;
AbstractPersistentObject mapped superclass
@MappedSuperclass
public abstract class AbstractPersistentObject implements PersistentObject, Serializable {
@Id
@Column(length = SIZE_32)
private String id = IdGenerator.createId();
@Version
private Integer version;
The stacktrace of the error:
Caused by: org.hibernate.MappingException: property [identifiers] not found on entity [my.package.collection.CollectionIdentifier]
at org.hibernate.mapping.PersistentClass.getProperty(PersistentClass.java:514) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.mapping.PersistentClass.getProperty(PersistentClass.java:525) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.cfg.IndexOrUniqueKeySecondPass.doSecondPass(IndexOrUniqueKeySecondPass.java:83) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1696) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1664) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:287) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:904) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
... 16 common frames omitted
Now the question is why at initialization level the context claims that this property should be available in the CollectionIdentifier entity.
EDIT:
The error occurs for several entities but only if the hierarchy level is bigger than 1
e.g.:
CollectionMaster
@OneToMany
Set<CollectionIdentifier>
works, but
Collection
@ManyToOne
Set<CollectionMaster>
@OneToMany
Set<CollectionIdentifer>
throws the error
AbstractPersistentObject) but there is no information about how to handle Inheritance (default strategy = SINGLE_TABLE)? Would suggest to try add@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)