如何解决带有@EmbeddedId 和单向@OneToMany 的外键和错误的列数
我有一个关于带有 @EmbeddedId 的 @OnetoMany 的问题。 这是错误: 从 ch.xxx.sp_model.sustainability.model.flows.flow.FlowTemplate 引用 ch.xxx.sp_model.sustainability.model.processes.Processtemplate 的外键具有错误的列数。应该是 2 这些是我的课程: 1.带有复合Key的流程模板:
@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 到 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;
但我不知道如何设置这种单向关系。 请注意,流程模板有一组流模板,这些流模板具有链接的流程模板(不是逆关系),但这不是双向关系。是简单的单向 onetoMany 和 ManyToOne。如何设置一对多?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。