I am using Spring Boot for creating my REST API. I have a "Component" class, which is as follows:
@Entity
public class Component {
@Id @GeneratedValue
private Long id;
private String name;
private String unit;
private double quantity;
public Component(){
}
public Component(Long id, String name, String unit, double quantity){
this.id = id;
this.name = name;
this.unit = unit;
this.quantity = quantity;
}
//getters
//setters
I have a product class which consists of "Component"s:
@Entity
public class Product{
@Id @GeneratedValue
private Long id;
private String name;
private Component productComponent;
}
Here is the Error that I am getting: It is highlighting the "private Component productComponent" line in the Product class, and saying the following:
Basic' attribute type should not be 'Persistence Entity'
What is the reason behind such error?
I fixed the above problem by adding @ManyToOne and @JoinColumn:
@Entity
public class Product{
@Id @GeneratedValue
private Long id;
private String name;
@ManyToOne
@JoinColumn
private Component productComponent;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.