外键和错误的列数,带有@embeddedid和单向@onetomany

v2g6jxz6  于 2021-07-16  发布在  Java
关注(0)|答案(0)|浏览(455)

我对一个有艾美身份证的“一个女人”有意见。这是错误:从ch..sp\u model.sustainability.model.flows.flowtemplate引用ch..sp\u model.sustainability.model.processs.processtemplate的外键的列数错误。应该是2这些是我的类:1.带有复合键的流程模板:

@Data
@Entity
public class ProcessTemplate {
    @EmbeddedId
    private ProcessTemplateId id;

    private String name;

    @ManyToOne
    @JoinColumn(name = "fk_referenced_flow_base", referencedColumnName = "id")
    private FlowBase referenceProduct;

    @ManyToOne
    @JoinColumn(name = "fk_process_base", referencedColumnName = "id")
    private ProcessBase processBase;

    @OneToMany
    @JoinColumn(name="processTemplate")
    private Set<FlowTemplate> flowsTemplate;

//    @OneToMany
//    @JoinColumn(name="processTemplate")
//    private Set<ElementaryFlowTemplate> elementaryFlowsTemplate;

    @ManyToOne
    @JoinColumn(name = "fk_source_info", referencedColumnName = "id")
    private SourceInfo sourceInfo;

    @Enumerated(EnumType.STRING)
    private Validation validation;

    @OneToMany(cascade = CascadeType.ALL,orphanRemoval = true)
    @JoinColumn(name="processTemplate")
    private Set<BaseEnvironmentalImpact> environmentalImpacts;

}

2.processtemplateid(processtemplate的复合id):

@Embeddable
public class ProcessTemplateId implements Serializable {

    @Column(name = "process_template_id")
    private UUID processTemplateId;

    @Column(name = "reference_product_id")
    private UUID referenceProductId;

    public ProcessTemplateId() {
    }

    public ProcessTemplateId(UUID processTemplateId, UUID referenceProductId) {
        this.processTemplateId = processTemplateId;
        this.referenceProductId = referenceProductId;
    }

    public UUID getProcessTemplateId() {
        return processTemplateId;
    }

    public UUID getReferenceProductId() {
        return referenceProductId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ProcessTemplateId)) return false;
        ProcessTemplateId that = (ProcessTemplateId) o;
        return Objects.equals(getProcessTemplateId(), that.getProcessTemplateId()) &&
                Objects.equals(getReferenceProductId(), that.getReferenceProductId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getProcessTemplateId(), getReferenceProductId());
    }
}

3.flowtemplate有一个@manytoone to processtemplate

@Data
@Entity
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class FlowTemplate extends AbstractFlowTemplate {

    private String name;

    @ManyToOne
    @JoinColumn(name = "fk_flow_base", referencedColumnName = "id")
    private FlowBase flowBase;

    @ManyToOne
    @JoinColumn(name = "fk_linked_process_base", referencedColumnName = "id")
    private ProcessBase linkedProcessBase;

    @ManyToOne
    @JoinColumns({@JoinColumn(name = "process_template_id", referencedColumnName = "process_template_id"),
            @JoinColumn(name = "reference_product_id", referencedColumnName = "reference_product_id")})
    private ProcessTemplate linkedProcessTemplate;

    @ManyToOne
    @JoinColumns({
            @JoinColumn(
                    name="process_id",
                    referencedColumnName = "process_id"),
            @JoinColumn(
                    name="reference_product_id",
                    referencedColumnName = "reference_product_id")
    })
    private ProcessTemplate processTemplate;
}

问题在于:

@OneToMany
    @JoinColumn(name="processTemplate")
    private Set<FlowTemplate> flowsTemplate;

但我不知道如何设置这种单向关系。注意,process tamplate有一组flowstemplate,这些flowstemplate有linkedprocesstemplate(不是反向关系),但这不是双向关系。是简单的单向一通和多通。我怎样才能设置一个域名?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题