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: Some questions about fetchprofiles
PostPosted: Wed Jul 28, 2010 2:37 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

FetchProfiles have a great potential in reducing the performance headaches that are inherent to Hibernate's automatic query generation. For me, Fetch profiles are not just about eager fetching of lazy associations but also about preventing Hibernate from generating all sorts of unwanted (left) joins when retrieving an entity that can cause all sorts of performance bottlenecks at the database level (tmp tables, file sorting etc). This also means that FetchProfiles are relevant in activating those joins when you do want the associations to load.

I have some questions about the limitations I seem to be running into (I'm using Hibernate 3.5.4.):

Let's say we have the following classes:

Code:
@FetchProfiles({
   @FetchProfile(name = "detail", fetchOverrides = {
      @FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN),
      @FetchProfile.FetchOverride(entity = Address.class, association = "city", mode = FetchMode.JOIN)
   })
})
Customer {
@OneToMany(fetch=FetchTye.LAZY)
private Order orders;

@ManyToOne(fetch=FetchTye.EAGER)
private Address mainAddress;
}

@FetchProfiles({
   @FetchProfile(name = "detail", fetchOverrides = {
      @FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN),
      @FetchProfile.FetchOverride(entity = Customer.class, association = "mainAddress", mode = FetchMode.JOIN),
      @FetchProfile.FetchOverride(entity = Consumer.class, association = "whines", mode = FetchMode.JOIN)
   })
})
Consumer extends Customer{
@OneToMany(fetch=FetchTye.LAZY)
List<Complaint> whines;
}

@FetchProfiles({
   @FetchProfile(name = "detail", fetchOverrides = {
      @FetchProfile.FetchOverride(entity = Order.class, association = "orderLines", mode = FetchMode.JOIN)
   })
})
Order{
@ManyToOne(fetch=FetchType.LAZY)
Customer

@OneToMany(fetch=FetchTye.LAZY)
private OrderLine orderLines;
}

@FetchProfiles({
   @FetchProfile(name = "detail", fetchOverrides = {
      @FetchProfile.FetchOverride(entity = GiftWrappedOrder.class, association = "wrappingMunchKin", mode = FetchMode.JOIN)
   })
})
GiftWrappedOrder extends Order{
//We want to be able to track the wrapping Munchkin for quality purposes
@ManyToOne(fetch=FetchTye.LAZY)
MunchKin wrappingMunchKin;
}

Address
@ManyToOne(fetch=FetchTye.LAZY)
private City city;


1. FetchProfile for GiftWrappedOrder. (hierarchy)
How do you specify a fetchprofile that will assure that the wrappingMuchKin will be eagerly joined when "detail" is active?

2. FetchProfile for City (deeper associations)
How do you specify a fetchprofile that will assure that cities will be eagerly joined when orders are fetched?

Basically, fetchprofiles work for me, but I have problems in the above mentioned cases.

I can't seem to be able to change the FetchMode for deeper associations and entities that are children of entities with active FetchProfiles themselves. And I'm also not sure about the placement of FetchProfile annotations.

Any suggestions are welcome.

Kind regards,

Marc


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.