@Embeddable
public class Picture {
private String name;
private int width;
private int height;
}
@Entity
@Table(name = "productCategory")
public class ProductCategory {
@ManyToOne(fetch = FetchType.LAZY)
private ProductCategory parent;
@Id
private Long id;
private String name;
@Embedded
private Picture picture;
@OneToMany(mappedBy = "parent")
private List<ProductCategory> children;
}
@Entity
@Table(name = "product")
@NamedEntityGraph(
name = "Product.withAll",
attributeNodes = {
@NamedAttributeNode(value = "category"),
}
)
public class Product {
@ManyToOne(fetch = FetchType.LAZY)
private ProductCategory category;
@Id
private Long id;
private String name;
@Embedded
private Picture picture;
}