-
1. Re: JPQL select relation traversal
wdfink Nov 24, 2010 2:44 AM (in response to quincy.mitchell)As I understand you right,
you will have the magazine with the loaded relation to article where only the article from 'John Doe' are included!?
The JPA select itself will not load the articles (except EAGER loading), only a SQL select the correct magazin.
If you access the articles you will get all articles of the magazin, nevertheless whether you use EAGER or LAZY loading.
If you want to have the article you might revert your select and use the relation to magazin (with eager loading) or do two selects.
SELECT y FROM Articles WHERE y.authorName = 'John Doe' and y.magazin.name='times'
The select to get the magazin for the 'two select' aproach will be the same as yours.
It depends to your requirements what you should use, two selects might be generate different SQL's over all.
But it will be a difficult and unstable optimization (for EJB2 I did such).
-
2. Re: JPQL select relation traversal
quincy.mitchell Nov 24, 2010 3:59 AM (in response to wdfink)Wolf-Dieter Fink wrote:
If you access the articles you will get all articles of the magazin, nevertheless whether you use EAGER or LAZY loading.
Correct. This is the issue. I don't want all articles of the magazine only those which hold to the given condition.
Wolf-Dieter Fink wrote:
If you want to have the article you might revert your select and use the relation to magazin (with eager loading) or do two selects.
Yes. This is the only way I have thought of to get the correct output. The cons of doing this are needing to filter out (intersect) results of multiple queries in the business code as well as the possibly high network traffic due to the individual results of a query could be large, but their intersection being small.
Does that make sense? Maybe I should elaborate?
-
3. JPQL select relation traversal
quincy.mitchell Feb 3, 2011 11:14 AM (in response to quincy.mitchell)The simplest answer that I have found is to make a database view and create a jpa entity for this view. So now in the same entity you'll have magazine names and their article authors.