-->
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: many to one lazy load not working
PostPosted: Wed Apr 26, 2006 6:27 pm 
Newbie

Joined: Thu Nov 17, 2005 6:37 pm
Posts: 13
We are attempting to lazy load an object property HiResImagePrivate defined in the User Logo mapping below as many-to-one.

The class type itself (File) and all sub classes (Image and Document) have been marked lazy="true" and also all properties and methods of these classes have been marked as virtual.

When we load a UserLogo object by id, an additional select query is always fired, which is loading in a huge image file! I have followed the documentation but have no idea why this is not working.

We have tried outer-join=true, outer-join=false, outer-join=auto on the many-to-one mapping, but no joy, any ideas people?

Hibernate version: 1.0.0.1

Mapping documents:

USER LOGO

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Logoers.BusinessLogic.UserLogo, Logoers.BusinessLogic" table="dbo.tblUserLogo">
<id name="ID" type="Int32" unsaved-value="0">
<column name="UserLogoID" sql-type="int" not-null="true" unique="true" index="PK_tblUserLogo"/>
<generator class="native" />
</id>
<property name="Name" type="String">
<column name="name" length="200" sql-type="varchar" not-null="true"/>
</property>
<property name="TotalColours" type="Int32">
<column name="totalColours" sql-type="int" not-null="true"/>
</property>
<property name="PmsInfo" type="String">
<column name="pmsInfo" length="50" sql-type="varchar" not-null="false"/>
</property>
<property name="Notes" type="String">
<column name="notes" length="2000" sql-type="varchar" not-null="false"/>
</property>
<property name="IsDisabled" type="Boolean">
<column name="isDisabled" sql-type="bit" not-null="true"/>
</property>
<component name="ChangeLog" class="Logoers.BusinessLogic.ChangeLog, Logoers.BusinessLogic">
<property name="CreatedOn" type="DateTime" column="createdOn" not-null="true" />
<property name="CreatedBy" type="String" column="createdBy" not-null="true" />
<property name="LastUpdatedOn" type="DateTime" column="LastUpdatedOn" not-null="true" />
<property name="LastUpdatedBy" type="String" column="lastUpdatedBy" not-null="true" />
</component>
<many-to-one name="ClientUser" class="Logoers.BusinessLogic.ClientUser, Logoers.BusinessLogic">
<column name="clientUserID" sql-type="int" not-null="true"/>
</many-to-one>
<many-to-one name="HiResImagePrivate" class="Logoers.BusinessLogic.Image, Logoers.BusinessLogic" >
<column name="hiResImageID" sql-type="int" not-null="true"/>
</many-to-one>
<many-to-one name="LoResImagePrivate" class="Logoers.BusinessLogic.Image, Logoers.BusinessLogic">
<column name="loResImageID" sql-type="int" not-null="true"/>
</many-to-one>
</class>
</hibernate-mapping>

FILE CLASS (SUB CLASSES OF IMAGE AND DOCUMENT)

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class
name="Logoers.BusinessLogic.File, Logoers.BusinessLogic"
table="dbo.tblFile"
discriminator-value="File" lazy="true">
<id name="ID" type="Int32" unsaved-value="0">
<column name="fileID" sql-type="int" not-null="true" unique="true" index="PK_tblFile"/>
<generator class="native" />
</id>
<discriminator column="fileClassRef" type="string" />
<property name="FileData" type="BinaryBlob">
<column name="fileData" length="2147483647" sql-type="image" not-null="false"/>
</property>
<property name="Name" type="String">
<column name="name" length="200" sql-type="varchar" not-null="true"/>
</property>
<property name="Extension" type="String">
<column name="extension" length="5" sql-type="varchar" not-null="true"/>
</property>
<property name="MimeType" type="String">
<column name="mimeType" length="50" sql-type="varchar" not-null="false"/>
</property>
<property name="Size" type="Int32">
<column name="size" sql-type="int" not-null="false"/>
</property>
<component name="ChangeLog" class="Logoers.BusinessLogic.ChangeLog, Logoers.BusinessLogic">
<property name="CreatedOn" type="DateTime" column="createdOn" not-null="true" />
<property name="CreatedBy" type="String" column="createdBy" not-null="true" />
<property name="LastUpdatedOn" type="DateTime" column="LastUpdatedOn" not-null="true" />
<property name="LastUpdatedBy" type="String" column="lastUpdatedBy" not-null="true" />
</component>
<subclass name="Logoers.BusinessLogic.Image, Logoers.BusinessLogic" discriminator-value="Image" lazy="true">
<property name="Height" type="Int32">
<column name="image_Height" sql-type="int" not-null="false"/>
</property>
<property name="Width" type="Int32">
<column name="image_Width" sql-type="int" not-null="false"/>
</property>
</subclass>
<subclass name="Logoers.BusinessLogic.Document, Logoers.BusinessLogic" discriminator-value="Document" lazy="true">
</subclass>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

We use this method for loading all objects by their id:

public static object Load(Type toLoadType, object objectID)
{
try
{
return GetSession().Load(toLoadType, objectID);
}
catch (Exception ex)
{
throw new Exception("NHibernate Load Failure: " + ex.Message, ex);
}
}

Name and version of the database you are using:

SQL Server 2005

The generated SQL (show_sql=true):

INITIAL SELECT

exec sp_executesql N'SELECT userlogo0_.UserLogoID as UserLogoID4_, userlogo0_.totalColours as totalCol3_4_, userlogo0_.isDisabled as isDisabled4_,
userlogo0_.createdOn as createdOn4_, userlogo0_.createdBy as createdBy4_, userlogo0_.LastUpdatedOn as LastUpda9_4_, userlogo0_.lastUpdatedBy as lastUpd10_4_,
userlogo0_.pmsInfo as pmsInfo4_, userlogo0_.loResImageID as loResIm13_4_, userlogo0_.name as name4_, userlogo0_.clientUserID as clientU11_4_, userlogo0_.notes
as notes4_, userlogo0_.hiResImageID as hiResIm12_4_, image1_.fileID as fileID0_, image1_.name as name0_, image1_.createdOn as createdOn0_, image1_.createdBy as
createdBy0_, image1_.LastUpdatedOn as LastUpd10_0_, image1_.lastUpdatedBy as lastUpd11_0_, image1_.mimeType as mimeType0_, image1_.fileData as fileData0_,
image1_.extension as extension0_, clientuser2_.userID as userID1_, clientuser2_.clientUser_clientCompanyID as clientU17_1_, clientuser2_.primaryUserAddressID as
primary16_1_, clientuser2_.isDisabled as isDisabled1_, clientuser2_.title as title1_, clientuser2_.lastName as lastName1_, clientuser2_.membershipUserID as
membersh3_1_, clientuser2_.receiveNewsletter as receive10_1_, clientuser2_.firstName as firstName1_, clientuser2_.fax as fax1_, clientuser2_.phone as phone1_,
clientuser2_.createdOn as createdOn1_, clientuser2_.createdBy as createdBy1_, clientuser2_.LastUpdatedOn as LastUpd14_1_, clientuser2_.lastUpdatedBy as
lastUpd15_1_, clientuser2_.mobile as mobile1_, client3_.companyID as companyID2_, client3_.client_isAccountHolder as client_16_2_, client3_.client_isCorporation
as client_15_2_, client3_.client_franchiseCompanyID as client_19_2_, client3_.client_corporationClientCompanyID as client_18_2_,
client3_.client_primaryClientUserID as client_17_2_, client3_.client_logoerUserID as client_20_2_, client3_.registrationNumber as registra4_2_, client3_.name as
name2_, client3_.taxRegistrationNumber as taxRegis5_2_, client3_.isDisabled as isDisabled2_, client3_.createdOn as createdOn2_, client3_.createdBy as
createdBy2_, client3_.LastUpdatedOn as LastUpda9_2_, client3_.lastUpdatedBy as lastUpd10_2_, client3_.primaryCompanyAddressID as primary14_2_,
client3_.publishingStatusClassifierID as publish11_2_, client3_.publishingAssignedToUserID as publish12_2_, client3_.publishingComments as publish13_2_,
useraddres4_.addressID as addressID3_, useraddres4_.userAddress_userID as userAdd21_3_, useraddres4_.contactMobile as contact11_3_, useraddres4_.state as
state3_, useraddres4_.countryClassifierID as country19_3_, useraddres4_.locality as locality3_, useraddres4_.address1 as address13_, useraddres4_.createdOn as
createdOn3_, useraddres4_.createdBy as createdBy3_, useraddres4_.LastUpdatedOn as LastUpd17_3_, useraddres4_.lastUpdatedBy as lastUpd18_3_,
useraddres4_.address3 as address33_, useraddres4_.address2 as address23_, useraddres4_.contactFax as contactFax3_, useraddres4_.isDisabled as isDisabled3_,
useraddres4_.postCode as postCode3_, useraddres4_.contactPhone as contact10_3_, useraddres4_.contactEmail as contact12_3_, useraddres4_.contactName as
contactN9_3_, useraddres4_.addressTypeClassifierID as address20_3_ FROM dbo.tblUserLogo userlogo0_ left outer join dbo.tblFile image1_ on
userlogo0_.loResImageID=image1_.fileID left outer join dbo.tblUser clientuser2_ on userlogo0_.clientUserID=clientuser2_.userID left outer join dbo.tblCompany
client3_ on clientuser2_.clientUser_clientCompanyID=client3_.companyID left outer join dbo.tblAddress useraddres4_ on
clientuser2_.primaryUserAddressID=useraddres4_.addressID WHERE userlogo0_.UserLogoID=@p0',N'@p0 int',@p0=1

ADDITIONAL SELECT FOR HiResImagePrivate

exec sp_executesql N'SELECT image0_.fileID as fileID0_, image0_.name as name0_, image0_.createdOn as createdOn0_, image0_.createdBy as createdBy0_,
image0_.LastUpdatedOn as LastUpd10_0_, image0_.lastUpdatedBy as lastUpd11_0_, image0_.mimeType as mimeType0_, image0_.fileData as fileData0_, image0_.extension
as extension0_ FROM dbo.tblFile image0_ WHERE image0_.fileID=@p0 and image0_.fileClassRef=''Image''',N'@p0 int',@p0=33


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.