简体   繁体   English

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

[英]Hibernate: a foreign key has the wrong number of column. should be 1

I'm trying to map to entities Report and ReportLookup:我正在尝试 map 到实体 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;

I don't know how to map composite foreign key.我不知道如何 map 复合外键。 Always get this error:总是得到这个错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [persistance-context.xml]: Invocation of init method failed; org.springframework.beans.factory.BeanCreationException:在 class 路径资源 [persistance-context.xml] 中定义名称为“entityManagerFactory”的 bean 创建错误:调用 init 方法失败; 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.嵌套异常是 org.hibernate.AnnotationException: A Foreign key refering ru.ocrv.ekasui.changemonitoring.maximo.entity.report.Report from ru.ocrv.ekasui.changemonitoring.maximo.entity.report.ReportLookup 的列数错误. should be 1应该是 1

I am not sure but you should try to change your @JoinColumns structure with the two Ids of your Class我不确定,但您应该尝试使用 Class 的两个 ID 更改您的 @JoinColumns 结构

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

Sorry but you can't add two columns with the same name, if you want to add a reportId in ReportLookup Table and ReportLookup in the Report Table delete the second @JoinColumn , in ReportLookup :抱歉,您不能添加两个具有相同名称的列,如果您想在ReportLookup表中添加一个reportId并在报告表中添加ReportLookup ,请在ReportLookup中删除第二个@JoinColumn

@ManyToOne
@JoinColumns({
        @JoinColumn(name = "appName", insertable = false, updatable = false)
})
private Report report; 

and in Report:并在报告中:

@OneToMany(fetch = FetchType.EAGER)
@JoinColumns({
        @JoinColumn(name = "reportName")
})
private Set<ReportLookup> lookupSet;

Second Solution you should add @JoinColumns in the principal entity第二种解决方案,您应该在主体实体中添加 @JoinColumns

@JsonProperty
@OneToMany(fetch = FetchType.EAGER)
@JoinColumns({
        @JoinColumn(name = "reportName"),
        @JoinColumn(name = "appName"),
})
private Set<ReportLookup> lookupSet;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate Mapping中的错误“外键引用的列数错误。 应该是2“ - Error in Hibernate Mapping “A Foreign key refering has the wrong number of column. should be 2” hibernate4:引用的外键列数错误。 应该是 2 - hibernate4: A Foreign key refering has the wrong number of column. should be 2 org.hibernate.AnnotationException:从Y引用X的外键具有错误的列数。 应该是2 - org.hibernate.AnnotationException: A Foreign key refering X from Y has the wrong number of column. should be 2 org.hibernate.AnnotationException:外键引用的列数错误。 应该是2 - org.hibernate.AnnotationException: A Foreign key refering has the wrong number of column. should be 2 AnnotationException: 引用的外键列数错误。 应该是 0 - AnnotationException: A Foreign key refering has the wrong number of column. should be 0 外键引用的列数错误。 应该是 2 - A Foreign key refering has the wrong number of column. should be 2 org.hibernate.AnnotationException:从y引用x的外键具有错误的列数。 应该是n - org.hibernate.AnnotationException:A Foreign key refering x from y has the wrong number of column. should be n AnnotationException:引用dayHibernate的外键…错误的列数。 应该是3 - AnnotationException: A Foreign key refering dayHibernate … wrong number of column. should be 3 Hibernate一对多关系:错误的列数。 应该是2 - Hibernate One to many Relationship : the wrong number of column. should be 2 Hibernate:外键的列数错误 - Hibernate: Foreign key has the wrong number of columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM