-->
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.  [ 3 posts ] 
Author Message
 Post subject: Casting error when doing a generic session.load<T>
PostPosted: Tue Apr 24, 2007 8:19 am 
Newbie

Joined: Tue Apr 24, 2007 8:05 am
Posts: 2
Hibernate version: 1.2

For some reason I get a casting error when doing a generic session.load

The following code fails with a cast exception:
Code:
ICat cat = (ICat)session.Load<Cat>("1bda0be1333b45cf9b7da7658dbea5ed");


The following code works and returns the proxy object based on ICat (see the mapping document)
Code:
ICat cat = (ICat)session.Load(typeof(Cat), "1bda0be1333b45cf9b7da7658dbea5ed");


What am I doing wrong here?

Mapping documents:
Code:
<class name="Cat" proxy="ICat" table="Cat" lazy="true">

    <!-- A 32 hex character is our surrogate key. It's automatically
            generated by NHibernate with the UUID pattern. -->
    <id name="Id">
      <column name="CatId" sql-type="char(32)" not-null="true"/>
      <generator class="uuid.hex" />
    </id>

    <!-- A cat has to have a name, but it shouldn' be too long. -->
    <property name="Name">
      <column name="Name" length="16" not-null="true" />
    </property>
    <property name="Sex" access="field.camelcase-underscore"/>
    <property name="Weight" access="field.camelcase-underscore"/>

    <list name="Flees" access="field.camelcase-underscore" cascade="all-delete-orphan">
      <key column="CatID"/>
      <index column="flee_number"/>
      <one-to-many class="Flee"/>
    </list>
  </class>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 8:51 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Load<Cat>(...) returns a Cat class, but the object you get from the database is not Cat. Don't use the generic form of Load in this case.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 10:37 am 
Newbie

Joined: Tue Apr 24, 2007 8:05 am
Posts: 2
Aha! Right! It's a proxy class of course! Thanks for the quick response!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.