不知道有没有人可以给我一些设计方面的建议?我遇到如下问题: org.hibernate.MappingException: 实体映射中的重复列,我知道这是因为我对 2 个嵌入式 setter/getter 使用了相同的列(“uom”)。但是,根据定义,重复的列由其他两列共享。谁能建议如何使用 JPA 注释进行设计?
public class FinalProfile extends BlockSegment implements Serializable, DeepCopy {
private static final long serialVersionUID = 1L;
...
private Measurement thresholdElevation;
...
private Measurement thresholdCrossingHeight;
public Measurement getThresholdCrossingHeight() {
return thresholdCrossingHeight;
}
public void setThresholdCrossingHeight(Measurement thresholdCrossingHeight) {
this.thresholdCrossingHeight = thresholdCrossingHeight;
}
public Measurement getThresholdElevation() {
return thresholdElevation;
}
public void setThresholdElevation(Measurement thresholdElevation) {
this.thresholdElevation = thresholdElevation;
}
...
}
@Entity
@EntityListeners( { AuditEntityListener.class, HasFlightProcedureIdEntityListener.class, HasAlpExpansionEntityListener.class } )
@Table ( name = "FINAL_PROFILE" )
@DiscriminatorValue ( "1" )
public class FinalProfileDo extends BlockSegmentDo
implements Audited, HasFlightProcedureId, HasAlpExpansionData {
private static final long serialVersionUID = 1L;
public static final Long BlockSegmentId = 1L;
private FinalProfile finalProfile;
...
@Embedded
@AttributeOverrides ( {
@AttributeOverride ( name = "value", column = @Column ( name = "THLD_CROSS_HEIGHT" ) )
, @AttributeOverride ( name = "uom", column = @Column ( name = "TCH_UOM" ) )
} )
public MeasurementDo getThresholdCrossingHeight() {
return (MeasurementDo)this.finalProfile.getThresholdCrossingHeight();
}
@DeepCopyType ( MeasurementDo.class )
public void setThresholdCrossingHeight(Measurement thresholdCrossingHeight) {
this.finalProfile.setThresholdCrossingHeight(thresholdCrossingHeight);
}
@Embedded
@AttributeOverrides({
@AttributeOverride( name ="value", column = @Column (name = "THLD_ELEVATION") )
, @AttributeOverride ( name = "uom", column = @Column ( name = "TCH_UOM"))
})
public MeasurementDo getThresholdElevation() {
return (MeasurementDo)this.finalProfile.getThresholdElevation();
}
@DeepCopyType ( MeasurementDo.class )
public void setThresholdElevation(MeasurementDo thresholdElevation) {
this.finalProfile.setThresholdElevation(thresholdElevation);
}
最佳答案
问题可能出在 name = "uom", column = @Column (name = "TCH_UOM")
行中,@Embedded
属性在实体中创建列表中,您尝试在同一个表中创建两个具有相同名称的列。
关于java - 列需要由 2 个嵌入式类型共享,但导致 "Repeated column in mapping for entity",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51603297/