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: Unable to cast object of type with join and <bags>
PostPosted: Wed Aug 26, 2009 5:12 pm 
Newbie

Joined: Wed Aug 26, 2009 4:58 pm
Posts: 6
My error occurrs when I try to execute the query created based on my mappings. Here is the code.

Code:
return AllGenericLookupValues = session.CreateCriteria(typeof(GenericLookup)).List<GenericLookup>();
However, when I copy and paste the query into sql it works. The reason for this is I am getting an "Unable to cast object of type" error. Is there something I should do differently in my xml files or in my DE files?

I have a parent table "GenericLookup" and a child table "GenericLookupValue". I want the results to be nested.
My GenericLookupBL class calls the GenericLookupRepository in my DAL

When the joined is performed I am referencing properties at the DE level in both the GenericLookup.cs and GenericLookupalue.cs (you should be able to see this in the xml below). If I have not provided enough information please let me know and I will provide more.

**** Here is the contents of my GenericLookup.hbm.xml ****
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   schema="dbSchema"
   xmlns="urn:nhibernate-mapping-2.2"
   assembly="assembly"
   namespace="namespace.DE">

  <class name="GenericLookup" table="GenericLookUp">
    <id column="LookupID" name="LookupID">
      <generator class="identity" />
    </id>
    <property column="Name" name="Name" />

    <bag name="GenericVal" fetch="join" cascade="all">
      <key column="LookupID" />
      <one-to-many class="GenericLookupValue" />
    </bag>

  </class>
</hibernate-mapping>
**** Here is the contents of my GenericLookupValue.hbm.xml ****
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   schema="dbSchema"
   xmlns="urn:nhibernate-mapping-2.2"
   assembly="assembly"
   namespace="namespace.DE">
   
   <class table="GenericLookupValue" name="GenericLookupValue">
      <id name="LookupValueID" type="Int32" column="LookupValueID" unsaved-value="0">
         <generator class="identity" />
      </id>
      <property name="LookupID" />
      <property name="Value" />
   </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Unable to cast object of type with join and <bags>
PostPosted: Thu Aug 27, 2009 2:25 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Code:
return AllGenericLookupValues = session.CreateCriteria(typeof(GenericLookup)).List<GenericLookup>();


What type is "AllGenericLookupValues" ? The query returns an IList<GenericLookup> !

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Unable to cast object of type with join and <bags>
PostPosted: Thu Aug 27, 2009 10:42 am 
Newbie

Joined: Wed Aug 26, 2009 4:58 pm
Posts: 6
Sorry, here you go.

Code:
var AllGenericLookupValues = session.CreateCriteria(typeof(GenericLookup)).List<GenericLookup>();
return AllGenericLookupValues;


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.