I have two entities: parent Customer and child Order.
Each Customer has 1,000,000 Orders for example, so it is not needed in any given time to load a Customer with all Orders but I want to have this ability to make join query on these two entities in JPA.
So because of this, I must create @OneToMany relationship for making join queries.
My question is: how to get query without making joinColumn because even in Lazy mode it is possible to load 1,000,000 objects!
I just want to get query on these object with where restrictions like native join.
If you don’t want the
@OneToManyrelationship implicitly set in yourCustomerclass than you don’t have to. You can execute JPQL queries (in very precise manner) without the marked relationship.Assume you have:
Then if you want to get all
Ordersfor particularCustomeryou can execute a simple JPQL query like that:In this way you can execute the code only when you’re really sure you want to fetch
Customer'sorders.I hope I’ve understood your problem correctly.