Hi,
I have a ManyToMany relation between a Product and Order class for a eCommerce application :
Product :
Code:
@Entity
@Table(name="PRODUCTS")
public class Product implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int productId;
private float price;
private String brand;
private int quantity;
@ManyToMany(mappedBy="products")
private List<Order> orders;
...
}
Order :
Code:
@Entity
@Table(name="ORDERS")
public class Order implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int orderId;
@ManyToMany(fetch=FetchType.EAGER)
@Fetch(FetchMode.SUBSELECT)
@JoinTable(name="OrdersProducts",
joinColumns=@JoinColumn(name="orderId", referencedColumnName="orderId"),
inverseJoinColumns=@JoinColumn(name="productId", referencedColumnName="productId") )
private List<Product> products;
.....
It works fine, but in my join table I only have the productId and orderId, I would like to have a "quantity" field. Is it possible to map a new field in a join table with an attribute from a collection ? Or is there a pattern to handle my problem ?
Thanx
Best regards,
John