Skip to main content

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

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


Back to the top