java - 列需要由 2 个嵌入式类型共享,但导致 "Repeated column in mapping for entity"

标签 java jpa

不知道有没有人可以给我一些设计方面的建议?我遇到如下问题: 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/

相关文章:

java - 我的程序不会停止

java - 生成的 JSP 类文件位于何处?

java - 如何使用 ModelMapper 将外键从 dto 映射到实体对象?

java - JPA/Hibernate - 删除子项会删除父项(从同一个表中)

java - jpa AttributeConverter 是否适用于查询子句?

java - Selenium 驱动程序通过在浏览器中切换选项卡而卡住

java - 如何在其他非 Activity 类Android的 Activity 中插入TextView?

java - 不要在 DialogFragment 上再次显示复选框

java - Custom Validation Annotation 引入了ConcurrentModificationException

java - JPA 默认注释是什么