列需要由2种嵌入式类型共享,但会导致“实体映射中的重复列”

时间:2018-07-30 22:51:04

标签: java jpa

我想知道是否有人可以给我关于设计的建议?我遇到以下问题:org.hibernate.MappingException:实体映射中的重复列,我知道这是因为我为2个嵌入式getter使用了同一列(“ uom”)。但是,根据定义,重复的列由其他2列共享。谁能建议如何使用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);
    }

1 个答案:

答案 0 :(得分:1)

问题可能出在name = "uom", column = @Column ( name = "TCH_UOM")行中,实体表中的@Embedded属性create列中,您尝试在同一表中创建两个具有相同名称的列。