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.  [ 4 posts ] 
Author Message
 Post subject: InvalidCastException problem
PostPosted: Thu May 15, 2008 11:56 am 
Newbie

Joined: Fri Dec 15, 2006 11:39 am
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
1.2.1

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >
   <class  name="Solex.DomainModel.Costs.IInventory" schema="Costs" table="Inventory" lazy="true">
      <id name="Index" type="Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
         <column name="InventoryIndex" sql-type="uniqueidentifier" not-null="true" unique="true" index="PK_Costs_Inventory_Index"/>
         <generator class="guid" />
      </id>
      <discriminator column="InventoryType"/>

      <property name="AdditionalInformation" type="String">
         <column name="Additional" sql-type="text" not-null="false" />
      </property>
      <property name="BookPrice" type="Decimal">
         <column name="BookPrice" sql-type="money" not-null="false" />
      </property>
      <property name="Cost" type="Decimal">
         <column name="Cost" sql-type="money" not-null="true" />
      </property>
      <many-to-one name="Dealer" cascade="save-update" class="Solex.DomainModel.Organizations.DealershipLocation">
         <column name="OrganizationIndex" sql-type="uniqueidentifier" not-null="true" />
      </many-to-one>
      <property name="Frieght" type="Decimal">
         <column name="Frieght" sql-type="money" not-null="false" />
      </property>
      <property name="GrossWeight" type="Int32">
         <column name="GrossWeight" sql-type="int" not-null="false" />
      </property>
      <property name="InStock" type="Boolean">
         <column name="InStock" sql-type="bit" not-null="false"/>
      </property>
      <property name="InventoryState" type="Solex.DomainModel.Costs.InventoryState, Solex">
         <column name="InventoryState" sql-type="bigint" not-null="true" />
      </property>
      <property name="InventoryType" type="Solex.DomainModel.Costs.InventoryType, Solex">
         <column name="InventoryTypeIndex" sql-type="bigint" not-null="true" />
      </property>
      <property name="InvoicePrice" type="Decimal">
         <column name="Invoice" sql-type="money" not-null="false" />
      </property>
      <property name="IsObsolete" type="Boolean">
         <column name="IsObsolete" length="1" sql-type="bit" not-null="false"/>
      </property>
      <property name="IsSold" type="Boolean">
         <column name="IsSold" length="1" sql-type="bit" not-null="false"/>
      </property>
      <property name="IsTrade" type="Boolean">
         <column name="IsTrade" length="1" sql-type="bit" not-null="false"/>
      </property>
      <property name="Length" type="Decimal">
         <column name="Length" sql-type="money" not-null="false" />
      </property>
      <property name="LicensePlateNumber" type="String">
         <column name="LicensePlateNumber" sql-type="varchar(20)" not-null="false" />
      </property>
      <many-to-one name="LicenseState" class="State" cascade="none">
         <column name="LicenseState" sql-type="char(2)" not-null="false"/>
      </many-to-one>
      <property name="LicenseYear" type="Int32">
         <column name="LicenseYear" sql-type="int" not-null="false" />
      </property>
      <property name="Make" type="String">
         <column name="Make" sql-type="varchar(100)" not-null="false" />
      </property>
      <property name="Model" type="String">
         <column name="Model" sql-type="varchar(100)" not-null="false" />
      </property>
      <property name="Odometer" type="Int32">
         <column name="Odometer" sql-type="int" not-null="false" />
      </property>
      <property name="OdometerReadDate" type="DateTime">
         <column name="OdometerReadDate" sql-type="smalldatetime" not-null="false" />
      </property>
      <property name="OdometerSticker" type="String">
         <column name="OdometerSticker" sql-type="varchar(50)" not-null="false" />
      </property>
      <bag name="Options" inverse="false" lazy="false" cascade="all-delete-orphan" schema="Addons" table="XrefInventoryAddons">
         <key column="InventoryIndex" />
         <many-to-many class="Solex.DomainModel.Addons.IAddon, Solex" column="AddonIndex"/>
      </bag>
      <property name="Price" type="Decimal">
         <column name="Price" sql-type="money" not-null="false"/>
      </property>
      <property name="ProductCode" type="String">
         <column name="ProductCode" sql-type="varchar(20)" not-null="false" />
      </property>
      <property name="StickerNumber" type="String">
         <column name="StickerNumber" sql-type="varchar(20)" not-null="false" />
      </property>
      <property name="StockNumber" type="String">
         <column name="StockNumber" sql-type="varchar(100)" not-null="false" />
      </property>
      <property name="TitleNumber" type="String">
         <column name="TitleNumber" sql-type="varchar(100)" not-null="false" />
      </property>
      <property name="VIN" type="String">
         <column name="VIN" sql-type="varchar(20)" not-null="false" />
      </property>
      <property name="WarrentyEndDate" type="DateTime">
         <column name="WarrentyEndDate" sql-type="smalldatetime" not-null="false" />
      </property>
      <property name="WarrentyStatus" type="Solex.DomainModel.Costs.WarrentyStatus, Solex">
         <column name="WarrentyStatusIndex" sql-type="bigint" not-null="false" />
      </property>
      <property name="Width" type="Decimal">
         <column name="Width" sql-type="money" not-null="false"/>
      </property>
      <property name="Year" type="Int32">
         <column name="Year" sql-type="int" not-null="false"/>
      </property>

      <!-- CAMPER ITEM-->
      <subclass name="Solex.DomainModel.Costs.Inventory.Camper" discriminator-value="CamperItem" proxy="Solex.DomainModel.Costs.IInventory">
         <property name="CamperType" type="Solex.DomainModel.Costs.CamperType, Solex">
            <column name="SubTypeIndex" sql-type="bigint" not-null="true" />
         </property>
         <property name="ExteriorColor" type="String">
            <column name="ExteriorColor" sql-type="varchar(20)" not-null="false" />
         </property>
         <property name="InteriorColor" type="String">
            <column name="InteriorColor" sql-type="varchar(20)" not-null="false" />
         </property>
         <property name="Style" type="String">
            <column name="Style" sql-type="varchar(100)" not-null="false" />
         </property>
      </subclass>

      <!-- RV ITEM-->
      <subclass name="Solex.DomainModel.Costs.Inventory.RV" discriminator-value="RVItem">
         <property name="Axles" type="Int32">
            <column name="Axles" sql-type="int" not-null="false"/>
         </property>
         <property name="ChassisMake" type="String">
            <column name="ChassisMake" sql-type="varchar(100)" not-null="false" />
         </property>
         <property name="ChassisModel" type="String">
            <column name="ChassisModel" sql-type="varchar(100)" not-null="false" />
         </property>
         <property name="ChassisStockNumber" type="String">
            <column name="ChassisStockNumber" sql-type="varchar(20)" not-null="false" />
         </property>
         <property name="ChassisYear" type="Int32">
            <column name="ChassisYear" sql-type="int" not-null="false" />
         </property>
         <property name="EngineType" type="Solex.DomainModel.Costs.EngineType, Solex">
            <column name="EngineTypeIndex" sql-type="bigint" not-null="false" />
         </property>
         <property name="ExteriorColor" type="String">
            <column name="ExteriorColor" sql-type="varchar(20)" not-null="false" />
         </property>
         <property name="InteriorColor" type="String">
            <column name="InteriorColor" sql-type="varchar(20)" not-null="false" />
         </property>
         <property name="KeyNumber" type="String">
            <column name="KeyNumber" sql-type="varchar(20)" not-null="false" />
         </property>
         <property name="NumberOfCylinders" type="Int32">
            <column name="NumberOfCylinders" length="4" sql-type="int" not-null="false"/>
         </property>
         <property name="RVType" type="Solex.DomainModel.Costs.RVType, Solex">
            <column name="SubTypeIndex" sql-type="bigint" not-null="true" />
         </property>
         <property name="SerialNumber" type="String">
            <column name="SerialNumber" sql-type="varchar(20)" not-null="false" />
         </property>
         <property name="Style" type="String">
            <column name="Style" sql-type="varchar(100)" not-null="false" />
         </property>
         <property name="UnitVIN" type="String">
            <column name="UnitVIN" sql-type="varchar(20)" not-null="false" />
         </property>
      </subclass>

      <!-- TRAILER ITEM-->
      <subclass name="Solex.DomainModel.Costs.Inventory.Trailer" discriminator-value="TrailerItem">
         <property name="Axles" type="Int32">
            <column name="Axles" sql-type="int" not-null="false"/>
         </property>
         <property name="TrailerType" type="Solex.DomainModel.Costs.TrailerType, Solex">
            <column name="SubTypeIndex" sql-type="bigint" not-null="true" />
         </property>
      </subclass>
   </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
         IInventory item = dao.GetById(new Guid("2A1D0DA4-37E5-48F7-B33F-DA2A8ACAF7AC"), false);

         Console.WriteLine(NHibernate.NHibernateUtil.GetClass(item));
         Console.WriteLine(item.GetSubType());
         Console.WriteLine(item.GetType());

         if (item is ICamper) {
            Console.WriteLine("item is ICamper");
         } else {
            Console.WriteLine("item is NOT ICamper");
         }
         if (item is IInventory) {
            Console.WriteLine("item is IInventory");
         } else {
            Console.WriteLine("item is NOT IInventory");
         }

         if (item is Solex.DomainModel.Costs.Inventory.Inventory) {
            Console.WriteLine("item is Inventory");
         } else {
            Console.WriteLine("item is NOT Inventory");
         }

         if (item is Camper) {
            Console.WriteLine("item is Camper");
         } else {
            Console.WriteLine("item is NOT Camper");
         }
         Camper camper = (Camper)item;

Full stack trace of any exception that occurs:
at Solex.UnitTests.Database.DomainModel.Costs.Inventory.CamperTest.Misc() in D:\code\Application\Solex\trunk\Solex.UnitTests\Database\DomainModel\Costs\Inventory\CamperTest.cs:line 78

i.e. is the last line in the previous section "Camper camper = (Camper)item;"

Name and version of the database you are using:
Microsoft Sql Server 2005

The generated SQL (show_sql=true):
exec sp_executesql N'SELECT iinventory0_.InventoryIndex as Inventor1_99_0_, iinventory0_.Additional as Additional99_0_, iinventory0_.BookPrice as BookPrice99_0_, iinventory0_.Cost as Cost99_0_, iinventory0_.OrganizationIndex as Organiza6_99_0_, iinventory0_.Frieght as Frieght99_0_, iinventory0_.GrossWeight as GrossWei8_99_0_, iinventory0_.InStock as InStock99_0_, iinventory0_.InventoryState as Invento10_99_0_, iinventory0_.InventoryTypeIndex as Invento11_99_0_, iinventory0_.Invoice as Invoice99_0_, iinventory0_.IsObsolete as IsObsolete99_0_, iinventory0_.IsSold as IsSold99_0_, iinventory0_.IsTrade as IsTrade99_0_, iinventory0_.Length as Length99_0_, iinventory0_.LicensePlateNumber as License17_99_0_, iinventory0_.LicenseState as License18_99_0_, iinventory0_.LicenseYear as License19_99_0_, iinventory0_.Make as Make99_0_, iinventory0_.Model as Model99_0_, iinventory0_.Odometer as Odometer99_0_, iinventory0_.OdometerReadDate as Odomete23_99_0_, iinventory0_.OdometerSticker as Odomete24_99_0_, iinventory0_.Price as Price99_0_, iinventory0_.ProductCode as Product26_99_0_, iinventory0_.StickerNumber as Sticker27_99_0_, iinventory0_.StockNumber as StockNu28_99_0_, iinventory0_.TitleNumber as TitleNu29_99_0_, iinventory0_.VIN as VIN99_0_, iinventory0_.WarrentyEndDate as Warrent31_99_0_, iinventory0_.WarrentyStatusIndex as Warrent32_99_0_, iinventory0_.Width as Width99_0_, iinventory0_.Year as Year99_0_, iinventory0_.SubTypeIndex as SubType35_99_0_, iinventory0_.ExteriorColor as Exterio36_99_0_, iinventory0_.InteriorColor as Interio37_99_0_, iinventory0_.Style as Style99_0_, iinventory0_.Axles as Axles99_0_, iinventory0_.ChassisMake as Chassis40_99_0_, iinventory0_.ChassisModel as Chassis41_99_0_, iinventory0_.ChassisStockNumber as Chassis42_99_0_, iinventory0_.ChassisYear as Chassis43_99_0_, iinventory0_.EngineTypeIndex as EngineT44_99_0_, iinventory0_.KeyNumber as KeyNumber99_0_, iinventory0_.NumberOfCylinders as NumberO46_99_0_, iinventory0_.SerialNumber as SerialN47_99_0_, iinventory0_.UnitVIN as UnitVIN99_0_, iinventory0_.InventoryType as Inventor2_0_ FROM Costs.Inventory iinventory0_ WHERE iinventory0_.InventoryIndex=@p0',N'@p0 uniqueidentifier',@p0='2A1D0DA4-37E5-48F7-B33F-DA2A8ACAF7AC'

exec sp_executesql N'SELECT options0_.InventoryIndex as Inventor1___1_, options0_.AddonIndex as AddonIndex1_, iaddon1_.AddonIndex as AddonIndex18_0_, iaddon1_.Code as Code18_0_, iaddon1_.[Cost] as column4_18_0_, iaddon1_.[Name] as column5_18_0_, iaddon1_.[Price] as column6_18_0_, iaddon1_.Quantity as Quantity18_0_, iaddon1_.RateCity as RateCity18_0_, iaddon1_.RateCounty as RateCounty18_0_, iaddon1_.RateState as RateState18_0_, iaddon1_.TaxableAmount as Taxable11_18_0_, iaddon1_.TaxParent as TaxParent18_0_, iaddon1_.AddonTypeIndex as AddonTy13_18_0_, iaddon1_.AddonType as AddonType0_ FROM Addons.XrefInventoryAddons options0_ left outer join Addons.Addons iaddon1_ on options0_.AddonIndex=iaddon1_.AddonIndex WHERE options0_.InventoryIndex=@p0',N'@p0 uniqueidentifier',@p0='2A1D0DA4-37E5-48F7-B33F-DA2A8ACAF7AC'

Debug level Hibernate log excerpt:
2008-05-15 09:02:13,716 DEBUG TestRunnerThread NHibernate.SQL - SELECT iinventory0_.InventoryIndex as Inventor1_99_0_, iinventory0_.Additional as Additional99_0_, iinventory0_.BookPrice as BookPrice99_0_, iinventory0_.Cost as Cost99_0_, iinventory0_.OrganizationIndex as Organiza6_99_0_, iinventory0_.Frieght as Frieght99_0_, iinventory0_.GrossWeight as GrossWei8_99_0_, iinventory0_.InStock as InStock99_0_, iinventory0_.InventoryState as Invento10_99_0_, iinventory0_.InventoryTypeIndex as Invento11_99_0_, iinventory0_.Invoice as Invoice99_0_, iinventory0_.IsObsolete as IsObsolete99_0_, iinventory0_.IsSold as IsSold99_0_, iinventory0_.IsTrade as IsTrade99_0_, iinventory0_.Length as Length99_0_, iinventory0_.LicensePlateNumber as License17_99_0_, iinventory0_.LicenseState as License18_99_0_, iinventory0_.LicenseYear as License19_99_0_, iinventory0_.Make as Make99_0_, iinventory0_.Model as Model99_0_, iinventory0_.Odometer as Odometer99_0_, iinventory0_.OdometerReadDate as Odomete23_99_0_, iinventory0_.OdometerSticker as Odomete24_99_0_, iinventory0_.Price as Price99_0_, iinventory0_.ProductCode as Product26_99_0_, iinventory0_.StickerNumber as Sticker27_99_0_, iinventory0_.StockNumber as StockNu28_99_0_, iinventory0_.TitleNumber as TitleNu29_99_0_, iinventory0_.VIN as VIN99_0_, iinventory0_.WarrentyEndDate as Warrent31_99_0_, iinventory0_.WarrentyStatusIndex as Warrent32_99_0_, iinventory0_.Width as Width99_0_, iinventory0_.Year as Year99_0_, iinventory0_.SubTypeIndex as SubType35_99_0_, iinventory0_.ExteriorColor as Exterio36_99_0_, iinventory0_.InteriorColor as Interio37_99_0_, iinventory0_.Style as Style99_0_, iinventory0_.Axles as Axles99_0_, iinventory0_.ChassisMake as Chassis40_99_0_, iinventory0_.ChassisModel as Chassis41_99_0_, iinventory0_.ChassisStockNumber as Chassis42_99_0_, iinventory0_.ChassisYear as Chassis43_99_0_, iinventory0_.EngineTypeIndex as EngineT44_99_0_, iinventory0_.KeyNumber as KeyNumber99_0_, iinventory0_.NumberOfCylinders as NumberO46_99_0_, iinventory0_.SerialNumber as SerialN47_99_0_, iinventory0_.UnitVIN as UnitVIN99_0_, iinventory0_.InventoryType as Inventor2_0_ FROM Costs.Inventory iinventory0_ WHERE iinventory0_.InventoryIndex=@p0; @p0 = '2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac'
2008-05-15 09:02:13,825 DEBUG TestRunnerThread NHibernate.Impl.BatcherImpl - Opened IDataReader, open IDataReaders: 1
2008-05-15 09:02:13,841 DEBUG TestRunnerThread NHibernate.Loader.Loader - processing result set
2008-05-15 09:02:13,841 DEBUG TestRunnerThread NHibernate.Loader.Loader - result set row: 0
2008-05-15 09:02:13,841 DEBUG TestRunnerThread NHibernate.Loader.Loader - result row: 2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac
2008-05-15 09:02:13,872 DEBUG TestRunnerThread NHibernate.Type.StringType - returning 'CamperItem' as column: Inventor2_0_
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Loader.Loader - Initializing object from DataReader: [Solex.DomainModel.Costs.Inventory.Camper#2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac]
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Loader.Loader - Hydrating entity: Solex.DomainModel.Costs.Inventory.Camper#2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Type.PersistentEnumType - returning '7' as column: SubType35_99_0_
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: Exterio36_99_0_
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: Interio37_99_0_
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: Style99_0_
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: Additional99_0_
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '5.0000' as column: BookPrice99_0_
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '5.0000' as column: Cost99_0_
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Type.GuidType - returning 'd2c29022-6063-4d58-8528-c411089003ec' as column: Organiza6_99_0_
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '5.0000' as column: Frieght99_0_
2008-05-15 09:02:13,903 DEBUG TestRunnerThread NHibernate.Type.Int32Type - returning '5' as column: GrossWei8_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.BooleanType - returning 'False' as column: InStock99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.PersistentEnumType - returning '4' as column: Invento10_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.PersistentEnumType - returning '2' as column: Invento11_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '5.0000' as column: Invoice99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.BooleanType - returning 'False' as column: IsObsolete99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.BooleanType - returning 'False' as column: IsSold99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.BooleanType - returning 'False' as column: IsTrade99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '5.0000' as column: Length99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: License17_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.StringType - returning 'AK' as column: License18_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.Int32Type - returning '1234' as column: License19_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: Make99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: Model99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.Int32Type - returning '123' as column: Odometer99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.DateTimeType - returning '5/10/2008' as column: Odomete23_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: Odomete24_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '5.0000' as column: Price99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: Product26_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: Sticker27_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: StockNu28_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: TitleNu29_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '123' as column: VIN99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.DateTimeType - returning '5/10/2008' as column: Warrent31_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.PersistentEnumType - returning '1' as column: Warrent32_99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '5.0000' as column: Width99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Type.Int32Type - returning '1990' as column: Year99_0_
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Loader.Loader - done processing result set (1 rows)
2008-05-15 09:02:13,919 DEBUG TestRunnerThread NHibernate.Driver.NHybridDataReader - running NHybridDataReader.Dispose()
2008-05-15 09:02:13,934 DEBUG TestRunnerThread NHibernate.Impl.BatcherImpl - Closed IDataReader, open IDataReaders :0
2008-05-15 09:02:13,934 DEBUG TestRunnerThread NHibernate.Impl.BatcherImpl - Closed IDbCommand, open IDbCommands: 0
2008-05-15 09:02:13,934 DEBUG TestRunnerThread NHibernate.Loader.Loader - total objects hydrated: 1
2008-05-15 09:02:13,934 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - resolving associations for: [Solex.DomainModel.Costs.Inventory.Camper#2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac]
2008-05-15 09:02:13,934 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - loading [DealershipLocation#d2c29022-6063-4d58-8528-c411089003ec]
2008-05-15 09:02:14,091 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - loading [State#AK]
2008-05-15 09:02:14,122 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - creating collection wrapper:[Solex.DomainModel.Costs.IInventory.Options#2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac]
2008-05-15 09:02:14,138 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - done materializing entity [Solex.DomainModel.Costs.Inventory.Camper#2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac]
2008-05-15 09:02:14,138 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - initializing non-lazy collections
2008-05-15 09:02:14,138 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - initializing collection [Solex.DomainModel.Costs.IInventory.Options#2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac]
2008-05-15 09:02:14,138 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - checking second-level cache
2008-05-15 09:02:14,138 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - collection not cached
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Loader.Loader - loading collection: [Solex.DomainModel.Costs.IInventory.Options#2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac]
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Impl.BatcherImpl - Opened new IDbCommand, open IDbCommands: 1
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Impl.BatcherImpl - Building an IDbCommand object for the SqlString: SELECT options0_.InventoryIndex as Inventor1___1_, options0_.AddonIndex as AddonIndex1_, iaddon1_.AddonIndex as AddonIndex18_0_, iaddon1_.Code as Code18_0_, iaddon1_.[Cost] as column4_18_0_, iaddon1_.[Name] as column5_18_0_, iaddon1_.[Price] as column6_18_0_, iaddon1_.Quantity as Quantity18_0_, iaddon1_.RateCity as RateCity18_0_, iaddon1_.RateCounty as RateCounty18_0_, iaddon1_.RateState as RateState18_0_, iaddon1_.TaxableAmount as Taxable11_18_0_, iaddon1_.TaxParent as TaxParent18_0_, iaddon1_.AddonTypeIndex as AddonTy13_18_0_, iaddon1_.AddonType as AddonType0_ FROM Addons.XrefInventoryAddons options0_ left outer join Addons.Addons iaddon1_ on options0_.AddonIndex=iaddon1_.AddonIndex WHERE options0_.InventoryIndex=?
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.GuidType - binding '2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac' to parameter: 0
2008-05-15 09:02:14,153 INFO TestRunnerThread NHibernate.Loader.Loader - SELECT options0_.InventoryIndex as Inventor1___1_, options0_.AddonIndex as AddonIndex1_, iaddon1_.AddonIndex as AddonIndex18_0_, iaddon1_.Code as Code18_0_, iaddon1_.[Cost] as column4_18_0_, iaddon1_.[Name] as column5_18_0_, iaddon1_.[Price] as column6_18_0_, iaddon1_.Quantity as Quantity18_0_, iaddon1_.RateCity as RateCity18_0_, iaddon1_.RateCounty as RateCounty18_0_, iaddon1_.RateState as RateState18_0_, iaddon1_.TaxableAmount as Taxable11_18_0_, iaddon1_.TaxParent as TaxParent18_0_, iaddon1_.AddonTypeIndex as AddonTy13_18_0_, iaddon1_.AddonType as AddonType0_ FROM Addons.XrefInventoryAddons options0_ left outer join Addons.Addons iaddon1_ on options0_.AddonIndex=iaddon1_.AddonIndex WHERE options0_.InventoryIndex=@p0
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.SQL - SELECT options0_.InventoryIndex as Inventor1___1_, options0_.AddonIndex as AddonIndex1_, iaddon1_.AddonIndex as AddonIndex18_0_, iaddon1_.Code as Code18_0_, iaddon1_.[Cost] as column4_18_0_, iaddon1_.[Name] as column5_18_0_, iaddon1_.[Price] as column6_18_0_, iaddon1_.Quantity as Quantity18_0_, iaddon1_.RateCity as RateCity18_0_, iaddon1_.RateCounty as RateCounty18_0_, iaddon1_.RateState as RateState18_0_, iaddon1_.TaxableAmount as Taxable11_18_0_, iaddon1_.TaxParent as TaxParent18_0_, iaddon1_.AddonTypeIndex as AddonTy13_18_0_, iaddon1_.AddonType as AddonType0_ FROM Addons.XrefInventoryAddons options0_ left outer join Addons.Addons iaddon1_ on options0_.AddonIndex=iaddon1_.AddonIndex WHERE options0_.InventoryIndex=@p0; @p0 = '2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac'
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Impl.BatcherImpl - Opened IDataReader, open IDataReaders: 1
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Loader.Loader - result set contains (possibly empty) collection: [Solex.DomainModel.Costs.IInventory.Options#2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac]
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - uninitialized collection: initializing
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Loader.Loader - processing result set
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Loader.Loader - result set row: 0
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.GuidType - returning '6ce80589-5847-452d-9793-1f2c43930815' as column: AddonIndex18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Loader.Loader - result row: 6ce80589-5847-452d-9793-1f2c43930815
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.StringType - returning 'GeneralOptionItem' as column: AddonType0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Loader.Loader - Initializing object from DataReader: [Solex.DomainModel.Addons.GeneralOption#6ce80589-5847-452d-9793-1f2c43930815]
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Loader.Loader - Hydrating entity: Solex.DomainModel.Addons.GeneralOption#6ce80589-5847-452d-9793-1f2c43930815
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.StringType - returning '1' as column: Code18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '0.0000' as column: column4_18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.StringType - returning 'name' as column: column5_18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '0.0000' as column: column6_18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.Int32Type - returning '0' as column: Quantity18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '0.0000' as column: RateCity18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '0.0000' as column: RateCounty18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '0.0000' as column: RateState18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.DecimalType - returning '0.0000' as column: Taxable11_18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.GuidType - returning null as column: TaxParent18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.PersistentEnumType - returning '0' as column: AddonTy13_18_0_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.GuidType - returning '2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac' as column: Inventor1___1_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Loader.Loader - found row of collection: [Solex.DomainModel.Costs.IInventory.Options#2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac]
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - reading row
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Type.GuidType - returning '6ce80589-5847-452d-9793-1f2c43930815' as column: AddonIndex1_
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - loading [IAddon#6ce80589-5847-452d-9793-1f2c43930815]
2008-05-15 09:02:14,153 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - attempting to resolve [IAddon#6ce80589-5847-452d-9793-1f2c43930815]
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - resolved object in session cache [Solex.DomainModel.Addons.IAddon#6ce80589-5847-452d-9793-1f2c43930815]
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Loader.Loader - done processing result set (1 rows)
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Driver.NHybridDataReader - running NHybridDataReader.Dispose()
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Impl.BatcherImpl - Closed IDataReader, open IDataReaders :0
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Impl.BatcherImpl - Closed IDbCommand, open IDbCommands: 0
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Loader.Loader - total objects hydrated: 1
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - resolving associations for: [Solex.DomainModel.Addons.GeneralOption#6ce80589-5847-452d-9793-1f2c43930815]
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - done materializing entity [Solex.DomainModel.Addons.GeneralOption#6ce80589-5847-452d-9793-1f2c43930815]
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - 1 collections were found in result set
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - collection fully initialized: [Solex.DomainModel.Costs.IInventory.Options#2a1d0da4-37e5-48f7-b33f-da2a8acaf7ac]
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - 1 collections initialized
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Loader.Loader - done loading collection
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - collection initialized
2008-05-15 09:02:14,169 DEBUG TestRunnerThread NHibernate.Loader.Loader - done entity load
2008-05-15 09:02:14,263 DEBUG TestRunnerThread NHibernate.Transaction.AdoTransaction - rollback
2008-05-15 09:02:14,263 DEBUG TestRunnerThread NHibernate.Transaction.AdoTransaction - running AdoTransaction.Dispose()
2008-05-15 09:02:14,263 DEBUG TestRunnerThread NHibernate.Impl.ConnectionManager - aggressively releasing database connection
2008-05-15 09:02:14,263 DEBUG TestRunnerThread NHibernate.Connection.ConnectionProvider - Closing connection
2008-05-15 09:02:14,278 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - transaction completion
2008-05-15 09:02:14,278 DEBUG TestRunnerThread NHibernate.Impl.SessionImpl - closing session
2008-05-15 09:02:14,278 DEBUG TestRunnerThread NHibernate.Impl.BatcherImpl - running BatcherImpl.Dispose(true)

Problems with Session and transaction handling?
The problem is i am trying to case the IInventory interface what is loading a Camper object as a Camper and the InvalidCastException is being thrown.

The exact error is Solex.UnitTests.Database.DomainModel.Costs.Inventory.CamperTest.Misc:
System.InvalidCastException : Unable to cast object of type 'ProxyInterfaceSystemSystemObject_NHibernate_ProxyINHibernateProxy_Solex_DomainModel_CostsIInventory_System_Runtime_SerializationISerializable' to type 'Solex.DomainModel.Costs.Inventory.Camper'.

Since I have been having problems I have moved the code into a unit test so that it is easier to make changes and test those changes in an isolated environment.

Output of the above code
Solex.DomainModel.Costs.Inventory.Camper
Fifth Wheel
ProxyInterfaceSystemSystemObject_NHibernate_ProxyINHibernateProxy_Solex_DomainModel_CostsIInventory_System_Runtime_SerializationISerializable
item is NOT ICamper
item is IInventory
item is NOT Inventory
item is NOT Camper

I have verified that it is being stored properly

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject: InvalidCastException problem
PostPosted: Wed May 21, 2008 10:00 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

Your log indicates: item is NOT Camper
Then you get an InvalidCastException trying to cast it to a Camper.

This seems correct.

If you are using proxies (lazy='true'), then NHibernate cannot create the 'correct' class from only the Id. Try setting your class to lazy='false' to see if you get the correct class back.

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/performance.html#performance-fetching-proxies
(specifically the bit that says ' ...instances of Cat will never be castable to DomesticCat, even if the underlying instance is an instance of DomesticCat ...')

Regards,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 21, 2008 10:13 am 
Newbie

Joined: Fri Dec 15, 2006 11:39 am
Posts: 7
Thanks.

In order to keep the lazy loading, for performance improvement, i learned that I just have to load the object as the correct type after i load it generically.


Top
 Profile  
 
 Post subject: Don't use Interfaces as proxy, use the same class instead
PostPosted: Tue Jul 01, 2008 3:27 am 
Newbie

Joined: Tue Jun 20, 2006 6:54 am
Posts: 3
you use IInventory as the proxy. Do not do that. This makes nhibernate creates a proxy that implements this interface only, without extending the class.

Instead, remove the proxy element in the mapping of the class (default is the class itself), and make all public and protected methods virtual. This will enable nhibernate to extend your class and create a proxy that is castable to this class and any of its parents.


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

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.