'SpringJPA: Multiple Tables with Multiple Columns map to Attribute Table

I have: BIKE table: brand, color, condition. BOOK table: name, color, condition. ATTRIBUTE table: id, catetory, value. (eg: 1, color, red; 2, color, white; 3, condition, new; 4, condition, old)

The color and condition in BIKE and BOOK are all linked to ATTRIBUTE with attribute.id. I am getting exceptions, what am I doing wrong?

in Bike.java:

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "color")
private Attribute color;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "condition")
private Attribute condition;

in Book.java:

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "color")
private Attribute color;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "condition")
private Attribute condition;

in Attribute.java:

@OneToMany(mappedBy = "color", fetch = FetchType.LAZY,
        cascade = CascadeType.ALL)
Set<Bike> bikeSet;

@OneToMany(mappedBy = "condition", fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    Set<Bike> bikeSet;

@OneToMany(mappedBy = "color", fetch = FetchType.LAZY,
        cascade = CascadeType.ALL)
Set<Book> bookSet;

@OneToMany(mappedBy = "condition", fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    Set<Book> bookSet;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source