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: N+1 Problem even though im calling .Expand - Please help Opt
PostPosted: Sat Mar 06, 2010 10:24 am 
Newbie

Joined: Mon Feb 22, 2010 1:35 pm
Posts: 3
Hi,

I have a One - To - One relationship


Product may have 0 or 1 CustomItem
CustomItem refrences Product


my database model simplified is


Product table - columns - ProductId, CutomItemId
Custom Item table - columns - CustomItemid, Additional information


public class Product
{
public virtual int Id { get; set; }
public virtual CustomItem CustomItem { get; set; }
}


public class CustomItem
{
public virtual int Id { get; set; }
public virtual string AdditionalInformation { get; set; }
public virtual Product Product { get; set; }
}


my overrides (im using auto mapping)
public class ProductMapOverride : IAutoMappingOverride<Product>
{
public void Override(AutoMap<Product> map)
{
map.References(x => x.CustomItem)
.Unique()
.TheColumnNameIs("CustomItemId")
.LazyLoad()
.Cascade.None();
}
}


public class CustomItemMapOverride :
IAutoMappingOverride<CustomItem>
{
public void Override(AutoMap<CustomItem> map)
{
map.HasOne(x => x.Product)
.PropertyRef(p => p.CustomItem)
.Cascade.All();
}
}


When i query my repository calling .Expand("CustomItem")


in my profiler, this is what i see..
SELECT this_.ProductId as ProductId0_1_,
this_.CustomItemId as CustomIt2_0_1_,
customitem2_.CustomItemId as CustomIt1_1_0_,
customitem2_.AdditionalInformation as Addition2_1_0_
FROM `Product` this_
left outer join `CustomItem` customitem2_
on this_.CustomItemId = customitem2_.CustomItemId


this looks good - it has asked for the custom item info


but then i get n+1 of these
SELECT product0_.ProductId as ProductId0_0_,
product0_.CustomItemId as CustomIt2_0_0_
FROM `Product` product0_
WHERE product0_.CustomItemId =? p0


can any one shed any light on how i can get rid of this N+1 problem.
Its driving me crazy


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.