Есть класс Product:
@Entity
@Table(name = "Products")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@ManyToOne(targetEntity = Type.class)
@JoinColumn(name = "type")
private Set<Type> type = new HashSet<Type>();
@ManyToOne(targetEntity = Brand.class)
@JoinColumn(name = "brand")
private Set<Brand> brand = new HashSet<Brand>();
private String title;
private long count;
private long price;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "product_id")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Set<Type> getType() {
return type;
}
public void setType(Set<Type> type) {
this.type = type;
}
public Set<Brand> getBrand() {
return brand;
}
public void setBrand(Set<Brand> brand) {
this.brand = brand;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
}
public long getPrice() {
return price;
}
public void setPrice(long price) {
this.price = price;
}
}
И класс Brand:
@Entity
@Table(name = "Brands")
public class Brand {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String brand;
@OneToMany(mappedBy = "Brands")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getTitle() {
return brand;
}
public void setTitle(String brand) {
this.brand = brand;
}
@Override
public String toString() {
return "Brand {" + "id=" + id + ", brand=" + brand + '}';
}
}
Запускается нормально, но вылетает ошибка:
java.lang.IllegalArgumentException: Can not set java.util.Set field com.alpha.bean.Product.brand to com.alpha.bean.Brand
Не могу понять, в чем проблема