I am trying to model this relationship following this link http://www.javaworld.com/javaworld/jw-01-2008/images/datamodel.gif
Its the usual Many to Many relationship bet
There is no concept of having additional persistent attribute in relation in JPA (2.0). That's why relation with property is actually intermediate entity.
From both Order and Product entities, you need one-to-many relationship to new entity. Because of bidirectional relationship, new entity will have many-to-one relationships to Order and Product.
You need to go for something like this (shows only relationships, id's and other mappings stripped away):
@Entity
@Table(name="order_item")
public class OrderItem {
@ManyToOne
private Order order;
@ManyToOne
private Product product;
}
@Entity
public class Order {
@OneToMany (mappedBy = "order")
private Set orderItems;
}
@Entity
public class Product {
@OneToMany(mappedBy = "product")
private Set orderItems;
}