After Reading the doc's Relations pages, I can use a many to many relation like this:
@Entity
public class Product {
@Id private Long id;
@ToMany
@JoinEntity(
entity = JoinProductsWithOrders.class,
sourceProperty = "productId",
targetProperty = "orderId"
)
private List<Order> ordersWithThisProduct;
}
@Entity
public class JoinProductsWithOrders {
@Id private Long id;
private Long productId;
private Long orderId;
}
@Entity
public class Order {
@Id private Long id;
}
Now, with this code, can I have a bi-directionel relations and access from an Order the list of Products associated with it? Or should I add a Product List in the Order class too? Something like this:
...
@Entity
public class Order {
@Id private Long id;
@ToMany //I don't know if this is corect btw.
private List<Product> productsForThisOrder;
}