简体   繁体   English

jpa hibernate 多对一关联中的错误

[英]Error in jpa hibernate association many to one

This my Product class that extends a BaseClass and I get error in这是我的产品 class 扩展了 BaseClass,我在

 @JoinColumn(name = "fk_supplier",referencedColumnName = "supplier_id")
 private Supplier supplier;

and error is 'Many To One' attribute type should not be 'Supplier'并且错误是“多对一”属性类型不应该是“供应商”

@Table
@Data
public class Product extends BaseEntity {
    @ManyToMany
    private List<Customer> customers = new ArrayList<>();
    @ManyToOne
    @JoinColumn(name = "fk_supplier",referencedColumnName = "supplier_id")
    private Supplier supplier;

}

And this is my Supplier Class这是我的供应商 Class

@Table
@Data
public class Supplier extends BaseEntity {
    @Column
    private boolean active;
    @Column
    private Date foundationDate;
    //Enum type to String type in mysql
    @Column
    @Enumerated(EnumType.STRING)
    private Type type;


    @OneToMany(targetEntity = Product.class)
    private List<Product> products = new ArrayList<>();
}

supplier_id column is defined under which entity?, means in the provided snippet for Supplier entity no such field is present. Supplier_id 列是在哪个实体下定义的?,意味着在提供的supplier_id Supplier实体片段中不存在这样的字段。 I hope the base entity will only be having columns that are generic and applicable over every entity you will be using.我希望基本实体只有通用的列,并且适用于您将使用的每个实体。 So if you specify referencedColumnName be sure that it align with what you have in the definitions.因此,如果您指定referencedColumnName ,请确保它与您在定义中的内容一致。 By default it will the primary key of the referenced entity, here primary key of Supplier table.默认情况下,它将是引用实体的主键,这里是Supplier表的主键。

Please try to do like this, it may solve the issue i think请尝试这样做,它可能会解决我认为的问题

@JoinColumn(name = "fk_supplier")
private Supplier supplier;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM