Hi All,
The two relevant class mappings for this issue, Address and PropertyRecord, are below. When I load an Address using a Criteria query, the PropertyRecord is loaded with the Address even though it is marked Lazy. In the query I make no reference to the PropertyRecord, I simply create a like expression on Street Name.
This is my only One-To-One relationship and I am wondering if I have set up the mapping incorrectly?
Thanks,
KC
Hibernate version: 1.2.0 Beta (latest Build)
Mapping documents:
Code:
<!--Generated from NHibernate.Mapping.Attributes on 2007-01-15 02:23:36Z.-->
<hibernate-mapping default-access="field.camelcase-underscore" xmlns="urn:nhibernate-mapping-2.2">
<class name="RealEstate.Data.Address, RealEstate.Data" lazy="true" table="`Address`">
<id name="Id" column="AddressId" unsaved-value="0">
<generator class="native" />
</id>
<property name="RBDI" column="RBDI" not-null="true" />
<property name="Title" column="Title" not-null="true" />
<property name="Street" column="Street" not-null="true" />
<property name="City" column="City" not-null="true" />
<property name="State" column="State" not-null="true" />
<property name="Zip" column="Zip" not-null="true" />
<property name="ZipPlus4" column="ZipPlus4" not-null="false" />
<property name="WalkSequence" column="WalkSequence" not-null="true" />
<property name="Endose" column="Endose" not-null="false" />
<property name="CityOrRural" column="CityOrRural" not-null="false" />
<property name="DPB" column="DPB" not-null="false" />
<property name="DPBC" column="DPBC" not-null="false" />
<property name="UpdateDate" column="UpdateDate" not-null="false" />
<property name="Latitude" column="Latitude" not-null="false" />
<property name="Longitude" column="Longitude" not-null="false" />
<many-to-one name="CarrierRoute" class="RealEstate.Data.CarrierRoute, RealEstate.Data" column="CarrierRouteId" cascade="save-update" />
<one-to-one name="PropertyRecord" class="RealEstate.Data.PropertyRecord, RealEstate.Data" cascade="all-delete-orphan" property-ref="Address" />
</class>
<class name="RealEstate.Data.PropertyRecord, RealEstate.Data" lazy="true" table="`PropertyRecord`">
<id name="Id" column="PropertyRecordId" unsaved-value="0">
<generator class="native" />
</id>
<property name="ParcelNumber" column="ParcelNumber" not-null="false" />
<property name="District" column="District" not-null="false" />
<property name="Situs" column="Situs" not-null="false" />
<property name="LegalDescription" column="LegalDescription" not-null="false" />
<property name="Owner" column="Owner" not-null="false" />
<property name="OwnerAddress" column="OwnerAddress" not-null="false" />
<property name="OwnerCity" column="OwnerCity" not-null="false" />
<property name="OwnerState" column="OwnerState" not-null="false" />
<property name="OwnerZip" column="OwnerZip" not-null="false" />
<property name="IsHomestead" column="IsHomestead" not-null="false" />
<property name="LotSize" column="LotSize" not-null="false" />
<property name="YearBuilt" column="YearBuilt" not-null="false" />
<property name="Quality" column="Quality" not-null="false" />
<property name="NumberOfBedrooms" column="NumberOfBedrooms" not-null="false" />
<property name="NumberOfBathrooms" column="NumberOfBathrooms" not-null="false" />
<property name="FloorArea" column="FloorArea" not-null="false" />
<property name="SlabArea" column="SlabArea" not-null="false" />
<property name="CrawlSpace" column="CrawlSpace" not-null="false" />
<property name="BasementArea" column="BasementArea" not-null="false" />
<property name="GarageArea" column="GarageArea" not-null="false" />
<many-to-one name="Address" class="RealEstate.Data.Address, RealEstate.Data" column="AddressId" unique="true" cascade="save-update" />
<many-to-one name="PropertyType" class="RealEstate.Data.PropertyType, RealEstate.Data" column="PropertyTypeId" cascade="save-update" />
<many-to-one name="Condition" class="RealEstate.Data.Condition, RealEstate.Data" column="ConditionId" cascade="save-update" />
<many-to-one name="Roofing" class="RealEstate.Data.Roofing, RealEstate.Data" column="RoofingId" cascade="save-update" />
<many-to-one name="Hvac" class="RealEstate.Data.Hvac, RealEstate.Data" column="HvacId" cascade="save-update" />
<many-to-one name="ExteriorWall" class="RealEstate.Data.ExteriorWall, RealEstate.Data" column="ExteriorWallId" cascade="save-update" />
<many-to-one name="Foundation" class="RealEstate.Data.Foundation, RealEstate.Data" column="FoundationId" cascade="save-update" />
<many-to-one name="StructureType" class="RealEstate.Data.StructureType, RealEstate.Data" column="StructureTypeId" cascade="save-update" />
<many-to-one name="StructureStyle" class="RealEstate.Data.StructureStyle, RealEstate.Data" column="StructureStyleId" cascade="save-update" />
<many-to-one name="Garage" class="RealEstate.Data.Garage, RealEstate.Data" column="GarageId" cascade="save-update" />
<set name="MiscImprovements" lazy="true" cascade="all-delete-orphan" inverse="true">
<key column="PropertyRecordId" />
<one-to-many class="RealEstate.Data.MiscImprovement, RealEstate.Data" />
</set>
<set name="PropertySales" lazy="true" cascade="all-delete-orphan" inverse="true">
<key column="PropertyRecordId" />
<one-to-many class="RealEstate.Data.PropertySale, RealEstate.Data" />
</set>
</class>
Name and version of the database you are using: MSSQL 2005
The generated SQL (show_sql=true):Code:
SELECT this_.AddressId as AddressId3_1_, this_.RBDI as RBDI3_1_, this_.Title as Title3_1_, this_.Street as Street3_1_, this_.City as City3_1_, this_.State as State3_1_, this_.Zip as Zip3_1_, this_.ZipPlus4 as ZipPlus8_3_1_, this_.WalkSequence as WalkSequ9_3_1_, this_.Endose as Endose3_1_, this_.CityOrRural as CityOrR11_3_1_, this_.DPB as DPB3_1_, this_.DPBC as DPBC3_1_, this_.UpdateDate as UpdateDate3_1_, this_.Latitude as Latitude3_1_, this_.Longitude as Longitude3_1_, this_.CarrierRouteId as Carrier17_3_1_, propertyre2_.PropertyRecordId as Property1_9_0_, propertyre2_.ParcelNumber as ParcelNu2_9_0_, propertyre2_.District as District9_0_, propertyre2_.Situs as Situs9_0_, propertyre2_.LegalDescription as LegalDes5_9_0_, propertyre2_.Owner as Owner9_0_, propertyre2_.OwnerAddress as OwnerAdd7_9_0_, propertyre2_.OwnerCity as OwnerCity9_0_, propertyre2_.OwnerState as OwnerState9_0_, propertyre2_.OwnerZip as OwnerZip9_0_, propertyre2_.IsHomestead as IsHomes11_9_0_, propertyre2_.LotSize as LotSize9_0_, propertyre2_.YearBuilt as YearBuilt9_0_, propertyre2_.Quality as Quality9_0_, propertyre2_.NumberOfBedrooms as NumberO15_9_0_, propertyre2_.NumberOfBathrooms as NumberO16_9_0_, propertyre2_.FloorArea as FloorArea9_0_, propertyre2_.SlabArea as SlabArea9_0_, propertyre2_.CrawlSpace as CrawlSpace9_0_, propertyre2_.BasementArea as Basemen20_9_0_, propertyre2_.GarageArea as GarageArea9_0_, propertyre2_.AddressId as AddressId9_0_, propertyre2_.PropertyTypeId as Propert23_9_0_, propertyre2_.ConditionId as Conditi24_9_0_, propertyre2_.RoofingId as RoofingId9_0_, propertyre2_.HvacId as HvacId9_0_, propertyre2_.ExteriorWallId as Exterio27_9_0_, propertyre2_.FoundationId as Foundat28_9_0_, propertyre2_.StructureTypeId as Structu29_9_0_, propertyre2_.StructureStyleId as Structu30_9_0_, propertyre2_.GarageId as GarageId9_0_ FROM [Address] this_ left outer join [PropertyRecord] propertyre2_ on this_.AddressId=propertyre2_.AddressId WHERE ((this_.Street like @p0 and this_.City = @p1) and this_.State = @p2)
2007-01-15 02:24:09,725 [3604] INFO NHibernate.Loader.Loader [(null)] <(null)> - SELECT propertyre0_.PropertyRecordId as Property1_9_0_, propertyre0_.ParcelNumber as ParcelNu2_9_0_, propertyre0_.District as District9_0_, propertyre0_.Situs as Situs9_0_, propertyre0_.LegalDescription as LegalDes5_9_0_, propertyre0_.Owner as Owner9_0_, propertyre0_.OwnerAddress as OwnerAdd7_9_0_, propertyre0_.OwnerCity as OwnerCity9_0_, propertyre0_.OwnerState as OwnerState9_0_, propertyre0_.OwnerZip as OwnerZip9_0_, propertyre0_.IsHomestead as IsHomes11_9_0_, propertyre0_.LotSize as LotSize9_0_, propertyre0_.YearBuilt as YearBuilt9_0_, propertyre0_.Quality as Quality9_0_, propertyre0_.NumberOfBedrooms as NumberO15_9_0_, propertyre0_.NumberOfBathrooms as NumberO16_9_0_, propertyre0_.FloorArea as FloorArea9_0_, propertyre0_.SlabArea as SlabArea9_0_, propertyre0_.CrawlSpace as CrawlSpace9_0_, propertyre0_.BasementArea as Basemen20_9_0_, propertyre0_.GarageArea as GarageArea9_0_, propertyre0_.AddressId as AddressId9_0_, propertyre0_.PropertyTypeId as Propert23_9_0_, propertyre0_.ConditionId as Conditi24_9_0_, propertyre0_.RoofingId as RoofingId9_0_, propertyre0_.HvacId as HvacId9_0_, propertyre0_.ExteriorWallId as Exterio27_9_0_, propertyre0_.FoundationId as Foundat28_9_0_, propertyre0_.StructureTypeId as Structu29_9_0_, propertyre0_.StructureStyleId as Structu30_9_0_, propertyre0_.GarageId as GarageId9_0_ FROM [PropertyRecord] propertyre0_ WHERE propertyre0_.AddressId=@p0
2007-01-15 02:24:09,756 [3604] INFO NHibernate.Loader.Loader [(null)] <(null)> - SELECT carrierrou0_.CarrierRouteId as CarrierR1_17_0_, carrierrou0_.RouteCode as RouteCode17_0_ FROM [CarrierRoute] carrierrou0_ WHERE carrierrou0_.CarrierRouteId=@p0