gpt4 book ai didi

java - Hibernate:外键的列数错误。应该是 1

转载 作者:行者123 更新时间:2023-12-01 20:17:32 25 4
gpt4 key购买 nike

我正在尝试映射到实体 Report 和 ReportLookup:

@Entity
public class Report extends AbstractMigrationObject implements Serializable {
@JsonIgnore
@Id
private Long reportId;
private String reportName;
private String appName;
private Integer reportNum;
private String issue;
@JsonProperty
@OneToMany(fetch = FetchType.EAGER)
@JoinColumns({
@JoinColumn(name = "reportName"),
@JoinColumn(name = "appName"),
})
private Set<ReportLookup> lookupSet;

@Entity
public class ReportLookup implements Serializable {
@JsonIgnore
@Id
private Long reportLookupId;
private String parameterName;
private String attributeName;
private String lookupName;
private Integer sequence;
private String labelOverride;
private String defaultValue;
private Integer required;
private Integer hidden;
private String reportName;
private String operator;
private Integer multiLookup;
private Integer reportNum;
private String appName;
@ManyToOne
@JoinColumns({
@JoinColumn(name = "appName", insertable = false, updatable = false),
@JoinColumn(name = "reportName", insertable = false, updatable = false)
})
private Report report;

我不知道如何映射复合外键。总是收到此错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [persistance-context.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: A Foreign key refering ru.ocrv.ekasui.changemonitoring.maximo.entity.report.Report from ru.ocrv.ekasui.changemonitoring.maximo.entity.report.ReportLookup has the wrong number of column. should be 1

最佳答案

我不确定,但你应该尝试使用你的类的两个 ID 更改你的 @JoinColumns 结构

    @JoinColumns({
@JoinColumn(name = "reportId", insertable = false, updatable = false),
@JoinColumn(name = "reportLookupId", insertable = false, updatable = false)
})

关于java - Hibernate:外键的列数错误。应该是 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58950886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com