所以我试图将EntityFieldValue的集合映射到EntityRow,其中一个连接列是一个公式,非常适合@OneToOne关系(' primaryKeyFieldValue& #39;在EntityRow类中),但在@OneToMany关系中使用时抛出异常(' secondaryKeyFieldValues'在EntityRow类中)。
Hibernate抛出 org.hibernate.MappingException :
Unable to find column with logical name: ENTITY_FIELD_ID in org.hibernate.mapping.Table(TBL_ENTITY_ROW) and its related supertables and secondary tables
是否可以使目标实体(EntityFieldValue)检查连接列是否存在,而不是所有者实体(EntityRow)?它是Hibernate中的一个错误吗?
使用Hibernate 5.0.10.Final。
实体:
public class Entity {
@Column(name = "ENTITY_ID", precision = 10)
private Long entityId;
...
}
public class EntityField {
@Column(name = "ENTITY_ID", precision = 10)
private Long entityId;
@Column(name = "ENTITY_FIELD_ID", precision = 10)
private Long entityFieldId;
...
}
public class EntityFieldValue {
@Column(name = "ENTITY_ID", precision = 10)
private Long entityId;
@Column(name = "ENTITY_ROW_ID", precision = 10)
private Long entityRowId;
@Column(name = "ENTITY_FIELD_ID", precision = 10)
private Long entityFieldId;
...
}
public class EntityRow {
@Column(name = "ENTITY_ID", precision = 10)
private Long entityId;
@Column(name = "ENTITY_ROW_ID", precision = 10)
private Long entityRowId;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumnsOrFormulas({
@JoinColumnOrFormula(column = @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID")),
@JoinColumnOrFormula(column = @JoinColumn(name = "ENTITY_ROW_ID", referencedColumnName = "ENTITY_ROW_ID")),
@JoinColumnOrFormula(formula = @JoinFormula(value = "( SELECT f.ENTITY_FIELD_ID FROM TBL_ENTITY_FIELD f WHERE f.ENTITY_ID = ENTITY_ID AND f.IS_KEY_FG = 1 )", referencedColumnName = "ENTITY_FIELD_ID"))})
private EntityFieldValue primaryKeyFieldValue;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumnsOrFormulas({
@JoinColumnOrFormula(formula = @JoinFormula(value = "( SELECT f.ENTITY_FIELD_ID FROM TBL_ENTITY_FIELD f WHERE f.ENTITY_ID = ENTITY_ID AND f.SECONDARY_KEY_FG = 1 )", referencedColumnName = "ENTITY_FIELD_ID")),
@JoinColumnOrFormula(column = @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)),
@JoinColumnOrFormula(column = @JoinColumn(name = "ENTITY_ROW_ID", referencedColumnName = "ENTITY_ROW_ID", insertable = false, updatable = false))})
private Set<EntityFieldValue> secondaryKeyFieldValues;
...
}
完整堆栈跟踪:
Caused by: org.hibernate.AnnotationException: Unable to map collection com.vermilion.vrs.jpa.entity.core.EntityRow.secondaryKeyFieldValues
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1555) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:865) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:780) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:719) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:54) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1655) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1623) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847) [hibernate-entitymanager-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874) [hibernate-entitymanager-5.0.10.Final.jar:5.0.10.Final]
at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:161) [wildfly-jpa-10.1.0.Final.jar:10.1.0.Final]
... 7 more
Caused by: org.hibernate.cfg.RecoverableException: Unable to find column with logical name: ENTITY_FIELD_ID in org.hibernate.mapping.Table(TBL_ENTITY_ROW) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:833) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:241) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1545) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
... 18 more
Caused by: org.hibernate.MappingException: Unable to find column with logical name: ENTITY_FIELD_ID in org.hibernate.mapping.Table(TBL_ENTITY_ROW) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:828) [hibernate-core-5.0.10.Final.jar:5.0.10.Final]
... 20 more