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

@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 
-- 
View this message in context: http://old.nabble.com/What%27s-the-difference-between-the-JoinFetch-Annotation-and-the-Fetch-Query-Hint-tp29640683p29641674.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top