-->
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.  [ 2 posts ] 
Author Message
 Post subject: Generics problem with many-to-many query?
PostPosted: Wed Nov 21, 2007 1:14 pm 
Beginner
Beginner

Joined: Thu Aug 17, 2006 3:20 pm
Posts: 21
Hibernate version:

1.2.0.2003

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Hybrid.Cms.Core.Website.WebSite, Hybrid.Cms.Core" table="WebSite" lazy="true">
     <id name="Id" column="WebSiteId" type="int">
        <generator class="native" />
     </id>
     <property name="Title" type="string" />
    <property name="ShortName" type="string" />
    <bag name="Pages" table="WebPage" lazy="true" cascade="all-delete-orphan" inverse="true" access="field.camelcase-underscore" order-by="PageIndex asc">
      <key column="WebSiteId" />
      <one-to-many class="Hybrid.Cms.Core.Website.WebPage, Hybrid.Cms.Core" />
    </bag>
    <joined-subclass name="Hybrid.Cms.Core.Website.DepartmentSite, Hybrid.Cms.Core" table="DepartmentSite">
      <key column="WebSiteId" />
      <property name="Address" access="property" type="String" />
      <property name="DirectorName" access="property" type="String" />
      <property name="DirectorEmail" access="property" type="String" />
      <property name="PhoneNumber" access="property" type="String" />
      <property name="FaxNumber" access="property" type="string" />
      <bag name="DepartmentEditors" table="DepartmentSite_DepartmentEditors" lazy="true" cascade="none" inverse="false" access="field.camelcase-underscore">
        <key>
          <column name="WebSiteId" sql-type="int" not-null="true" />
        </key>
        <many-to-many class="Hybrid.Cms.Core.User.HybridUser, Hybrid.Cms.Core">
          <column name="HybridUserId" sql-type="int" not-null="true" />
        </many-to-many>
      </bag>
    </joined-subclass>
    <joined-subclass name="Hybrid.Cms.Core.Website.SchoolSite, Hybrid.Cms.Core" table="SchoolSite">
      <key column="WebSiteId" />
      <property name="Address" access="property" type="String" />
      <property name="PrincipalName" access="property" type="String" />
      <property name="PrincipalEmail" access="property" type="String" />
      <property name="PhoneNumber" access="property" type="String" />
      <property name="FaxNumber" access="property" type="string" />
      <property name="Photo" access="property" type="string" />
      <bag name="SchoolAdmins" table="SchoolSite_SchoolAdmins" lazy="true" cascade="none" inverse="false" access="field.camelcase-underscore">
        <key>
          <column name="WebSiteId" sql-type="int" not-null="true" />
        </key>
        <many-to-many class="Hybrid.Cms.Core.User.HybridUser, Hybrid.Cms.Core">
          <column name="HybridUserId" sql-type="int" not-null="true" />
        </many-to-many>
      </bag>     
      <bag name="SchoolEditors" table="SchoolSite_SchoolEditors" lazy="true" cascade="none" inverse="false" access="field.camelcase-underscore">
        <key>
          <column name="WebSiteId" sql-type="int" not-null="true" />
        </key>
        <many-to-many class="Hybrid.Cms.Core.User.HybridUser, Hybrid.Cms.Core">
          <column name="HybridUserId" sql-type="int" not-null="true" />
        </many-to-many>
      </bag>
      <bag name="Teachers" table="SchoolSite_Teachers" lazy="true" cascade="none" inverse="true" access="field.camelcase-underscore">
        <key>
          <column name="WebSiteId" sql-type="int" not-null="true" />
        </key>
        <many-to-many class="Hybrid.Cms.Core.User.HybridUser, Hybrid.Cms.Core">
          <column name="HybridUserId" sql-type="int" not-null="true" />
        </many-to-many>
      </bag>
    </joined-subclass>
    <joined-subclass name="Hybrid.Cms.Core.Website.TeacherSite, Hybrid.Cms.Core" table="TeacherSite">
      <key column="WebSiteId" />
    </joined-subclass>
  </class>
</hibernate-mapping>

Full stack trace of any exception that occurs:
Code:
System.ArgumentException: The value "System.Object[]" is not of type "Hybrid.Cms.Core.Website.WebSite" and cannot be used in this generic collection.
Parameter name: value
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(String query, QueryParameters parameters, IList results)
NHibernate.ADOException: Could not execute query
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results)
at NHibernate.Impl.SessionImpl.Find[T](String query, QueryParameters parameters)
at NHibernate.Impl.QueryImpl.List[T]()
at Hybrid.Cms.Data.Tests.UserRepositoryMock.GetAllSchoolsForAdmin(IHybridUser user) in UserRepositoryTestCase.cs:line 31
at Hybrid.Cms.Data.Tests.UserRepositoryTestCase.Can_GetAllSchoolsForAdmin() in UserRepositoryTestCase.cs:line 182

Name and version of the database you are using:
SqlCe (testing)
Sql 2005 (production)

The generated SQL (show_sql=true):
Code:
select schoolsite0_.WebSiteId as WebSiteId10_0_, hybriduser2_.Id as Id0_1_, schoolsite0_.Address as Address12_0_, schoolsite0_.PrincipalName as Principa3_12_0_, schoolsite0_.PrincipalEmail as Principa4_12_0_, schoolsite0_.PhoneNumber as PhoneNum5_12_0_, schoolsite0_.FaxNumber as FaxNumber12_0_, schoolsite0_.Photo as Photo12_0_, schoolsite0_1_.Title as Title10_0_, schoolsite0_1_.ShortName as ShortName10_0_, hybriduser2_.UserGuid as UserGuid0_1_, hybriduser2_.Username as Username0_1_, hybriduser2_.Password as Password0_1_, hybriduser2_.LastName as LastName0_1_, hybriduser2_.FirstName as FirstName0_1_, hybriduser2_.Email as Email0_1_, hybriduser2_.WebSiteId as WebSiteId0_1_ from SchoolSite schoolsite0_ inner join WebSite schoolsite0_1_ on schoolsite0_.WebSiteId=schoolsite0_1_.WebSiteId inner join SchoolSite_SchoolAdmins schooladmi1_ on schoolsite0_.WebSiteId=schooladmi1_.WebSiteId inner join HybridUser hybriduser2_ on schooladmi1_.HybridUserId=hybriduser2_.Id where (hybriduser2_.Id=@p0); @p0 = '1'


Here is the query I am trying to use:

IQuery query = session.CreateQuery("from SchoolSite s inner join s.SchoolAdmins u where u = :user");
query.SetEntity("user", user);
return query.List<WebSite>();


This is a unidirectional association, so there is no inverse on HybridUser. I am trying to retrieve all SchoolSite's that HybridUser is in the collection SchoolAdmins. It seems to be something wrong with the query.List<SchoolSite>() generics.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 23, 2008 9:53 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
deleted


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.