Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] What's the difference between the JoinFetch Annotation and the Fetch-Query Hint

Hello James,

We are using version 2.1.1 of EL.
At the moment I can't send you the log file because we're hardly working on a fix for the
customer, and must heavily reduce the amount of SQL-Queries issued by our app. But I'll try to
send it as soon as possible.

I can't agree with you in what you say about batch fetching. We've got a bunch of JP queries
that lead to a tremendous amount of database queries as long as we had batch fetching in use. We
could reduce them by switching to join fetches.

Unfortunately join fetches have there own problems, as you can see in this and my other threads.

Regards, Michael

Am 08.09.2010 15:16, schrieb James Sutherland:
> 
> @JoinFetch means always join fetch the relationship for all queries.
> The query hint means just join fetch for this query.
> Both should work.  It is very odd that the hint or JPQL is not working.
> What version are you using?  Could you include the SQL log on finest.
> 
> You should also consider using batch fetching, which is more efficient for a
> OneToMany.
> 
> 
> Michael Simons wrote:
>>
>> Hello,
>>
>> I've got a simple one-many Association that I need to query in a single
>> select:
>> Product (1:N) LocalizedProduct
>> class Product {
>>  @OneToMany(cascade={CascadeType.PERSIST, CascadeType.REMOVE},
>> fetch=FetchType.LAZY,
>> mappedBy="product")
>> @JoinFetch(value=JoinFetchType.OUTER)
>> private Set<LocalizedProduct> locals = new HashSet<LocalizedProduct> (13);
>> }
>>
>> With the annotation JoinFetch it works like I'd have expected, but it
>> doesn't without the
>> annotation but giving a QueryHint:
>> TypedQuery<Product> query = em.createQuery ("SELECT p from Product p",
>> Product.class);
>> query.setHint(QueryHints.LEFT_FETCH, "p.locals");
>>
>> It also doesn't work with the query:
>> TypedQuery<Product> query = em.createQuery ("SELECT p from Product p join
>> fetch p.locals",
>> Product.class);
>>
>> In the last two cases I get (N+1) queries created by EL.
>>
>> What do I miss? What do I have to pay attention to?
>>
>> Kind Regards, Michael
>>
>>
> 
> 
> -----
> http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
> http://www.eclipse.org/eclipselink/
>  EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
> TopLink 
> Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
> http://wiki.oracle.com/page/TopLink TopLink 
> Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
> http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
> Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 



Back to the top