-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Nested fetch joins
PostPosted: Mon Aug 09, 2010 5:13 pm 
Newbie

Joined: Fri May 16, 2008 3:40 pm
Posts: 13
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.