Hi,
I do understand that Hibernate does not support multiple fetch joins from one entity to another. What elludes me is why it does not support fetch joins in nested queries.
Say I have the following classes:
Code:
class Category {
@Id
private Integer id;
private String name;
@OneToMany(mappedBy="category", cascade=CascadeType.ALL)
private Set<Product> products;
// ...
}
class Product {
@Id
private Integer id;
private String name;
@ManyToOne @JoinColumn
private Category category;
@OneToMany(mappedBy="product", cascade=CascadeType.ALL)
private Set<Price> prices;
// ...
}
class Price {
@Id
private Integer id;
private Date validFrom;
private int valueInCents;
@ManyToOne @JoinColumn
private Product product;
// ...
}
So a Category can have multiple products and a product has multiple prices. For me it is sensible to retrieve this in one query, but trying to do a query like
Code:
select c from Category c join fetch c.products p join fetch p.prices
fails with a HibernateSystemException "Cannot simultaneously fetch multiple bags".
So is this something that is just not supported by hibernate or is there a way to force hibernate to do this. Considering that I have 100s of categories, 10'000s of products and for each product a history involving up to 30 prices, the performance difference between a single query and some x-thousand subqueries is immense.
Thanks for helping.