Есть класс 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 = "brand", fetch = FetchType.LAZY)
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 + '}';
}
}
И класс Type:
@Entity
@Table(name = "Types")
public class Type {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String type;
@OneToMany(mappedBy = "type", fetch = FetchType.LAZY)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "Type {" + "id=" + id + ", type=" + type + '}';
}
}
Схема БД:
CREATE TABLE Brands
(ID BIGINT PRIMARY KEY AUTO_INCREMENT,
BRAND VARCHAR(100));
CREATE TABLE Types
(ID BIGINT PRIMARY KEY AUTO_INCREMENT,
TYPE VARCHAR(100));
CREATE TABLE Products
(ID BIGINT PRIMARY KEY AUTO_INCREMENT,
TYPE_ID BIGINT REFERENCES Types(ID),
BRAND_ID BIGINT REFERENCES Brands(ID),
TITLE VARCHAR(100),
COUNT BIGINT,
PRICE BIGINT);
Все запускается и работает, но в браузере при выводе данных из таблицы Products именно поля brand и type почему-то null. Второй день маюсь, не могу понять, в чем проблема.