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 Chris,

Adding Query Hint REFRESH seems to do it.
When do I have to set that hint to get the join and when can I omit it?


Kind Regards, Michael

Am 07.09.2010 15:32, schrieb Christopher Delahunt:
> Hello Michael,
> 
> Can you try adding the query.setHint(QueryHints.REFRESH, true) hint to your queries and see what
> the results are?  Also, does the join get added to the initial query? (you can see the SQL
> EclipseLink uses by turning logging on via the <property name="eclipselink.logging.level"
> value="FINE"/> persistence.xml tag )
> 
> Best Regards,
> Chris
> 
> On 07/09/2010 4:12 AM, 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
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>   
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 


Back to the top