-->
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: Problem with associations and querying
PostPosted: Wed Jul 25, 2007 9:08 am 
Newbie

Joined: Wed Jul 25, 2007 8:55 am
Posts: 1
Hi,

I'm having a problem with associations. Basically any attempt to use eager loading, or to create criteria spanning an association fails with the following exception:
Code:
The value "System.Object[]" is not of type "Domain.object1" and cannot be used in this generic collection.

at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType)
   at System.Collections.Generic.List`1.VerifyValueType(Object value)
   at System.Collections.Generic.List`1.System.Collections.IList.Add(Object item)
   at NHibernate.Util.ArrayHelper.AddAll(IList to, IList from)
   at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results)


Some representative mappings:
Code:
<class name="Domain.object1, Domain" table="object1">
   <id name="objectID" column="object_nbr" type="Int32">
      <generator class="assigned" />
   </id>
   <property name="prop1" column="prop1" type="Decimal" />
   <many-to-one name="Object2" class="Domain.object2, Domain"  column="object2_id" not-null="true" />
   <many-to-one name="Object3" class="Domain.object3, Domain" column="object3_id" not-null="true"/>
</class>
<class name="Domain.object2, Domain" table="object2">
   <id name="object2_id" column="object_nbr" type="Int32">
      <generator class="assigned" />
   </id>
   <property name="name" column="prop1" type="Decimal" />
        <set name="Object1s" inverse="true">
         <key column="object2_id" />
         <one-to-many class="Domain.object1, Domain" />
      </set>
</class>
<class name="Domain.object3, Domain" table="object3">
   <id name="object3_id" column="object_nbr" type="Int32">
      <generator class="assigned" />
   </id>
   <property name="name" column="prop1" type="Decimal" />
</class>


If I specify fetch=join on either of the many-to-one mappings then I get the exception above - the same happens if I attempt to use a criteria like so:

Code:
criteria = DetachedCriteria.For<Object1>()
                          .CreateCriteria("Object2")
                                    .Add(Expression.Eq("prop1", value));


Straightforward queries using just Object1 succeed OK (as long as the fetch mode is lazy)

It's most likely that I'm getting something wrong here, so can anyone point me in the right direction?


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.