Класс покупки:
package eg;
@javax.persistence.Embeddable
public class Purchase{
private Date purchaseDate;
private Double price;
private Integer quantity;
@javax.persistence.ManyToOne
private Item item;
// getters and setters
}
Класс заказа:
package eg;
@javax.persistence.Entity
public class Order {
@javax.persistence.ElementCollection(fetch = javax.persistence.FetchType.LAZY)
@javax.persistence.CollectionTable(
name = "purchase_items",
joinColumns = @JoinColumn( name = "order_id" )
)
java.util.Set<eg.Purchase> purchasedItems;
// getter and setter for purchasedItems
}