I currently have a structure as follows (pseudocode):
public class Order
{
@OneToMany(targetEntity = Orderline.class, fetch = FetchType.LAZY)
private List<Orderline> orderlines;
private Client client;
}
public class Orderline
{
@ManyToOne(mappedBy = 'orderlines')
private Order order;
private Client client;
}
public class Client
{
// your usual Client class, its contents aren't important for the question
}
Say that I can have an order with ID 123, which belongs to client X. I can also have an order with ID 123 which belongs to client Y. When lazy loading (or eager loading, for that matter), how can I know that when I fetch order with ID 123 for client X from the database, I won't be getting the orderlines from client Y? If JPA checks on the foreign key on the orderline side only, is there a way to add a check for the client when lazy (or eager) loading?
I would like to solve this without using specific implementations like Hibernate or Eclipselink so I can easily switch between implementations if necessary.