-->
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: query.List<prf_ProfileItemTitle>() is failing.
PostPosted: Mon Aug 13, 2007 8:55 pm 
Newbie

Joined: Mon Aug 13, 2007 8:49 pm
Posts: 9
I've done this before, but for some reason NHibernate can't set the returned objects into a generic list, it fails here:

In SessionImpl.cs:
Code:
#line 1758
         bool success = false;
         try
         {
            for (int i = q.Length - 1; i >= 0; i--)
            {
               ArrayHelper.AddAll(results, q[i].List(this, parameters));
            }
            success = true;
         }
         catch (HibernateException)
         {
            // Do not call Convert on HibernateExceptions
            throw;
         }
         catch (Exception e)
         {
            throw Convert(e, "Could not execute query");
      }


the actual error occurs in ArrayHelper.AddAll:

[ArrayHelper.cs, line 152]
Code:
      // NH-specific
      public static void AddAll(IList to, IList from)
      {
         foreach (object obj in from)
         {
            to.Add(obj);
         }
      }


for reference,
to.GetType().ToString() = "System.Collections.Generic.List`1[LightsCore.prf_ProfileItemTitle]"

It just seems like this function shouldn't even be running, and instead a generic-aware one should (somehow via reflection?)

I'm stuck! Please help... and thanks in advance! I have a feeling its something very silly on my part.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 5:05 am 
Beginner
Beginner

Joined: Wed Oct 04, 2006 8:57 am
Posts: 25
Can you post your code and mapping files.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 11:08 am 
Newbie

Joined: Mon Aug 13, 2007 8:49 pm
Posts: 9
Code:
            NHibernate.ISession session = NHibernate.NHibernateHttpModule.CurrentSession;
            NHibernate.IQuery query = session.CreateQuery("from prf_ProfileItemTitle as t join t.ProfileSection as s where s.SectionName=?")
               .SetString(0, sectionName);
            
            IList<LightsCore.prf_ProfileItemTitle> itemTitles = query.List<LightsCore.prf_ProfileItemTitle>();


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="LightsCore.prf_ItemAdapter, LT.Profiles.Data" table="prf.ItemAdapter">
      <id name="Id" type="Int32" unsaved-value="null">
         <column name="ItemAdapterID" length="4" sql-type="int" not-null="true" unique="true" index="PK_ItemTitleAdapter"/>
         <generator class="native" />
      </id>
      <property name="AdapterName" type="String">
         <column name="AdapterName" length="50" sql-type="varchar" not-null="true"/>
      </property>
      <property name="DataAdapterTypeName" type="String">
         <column name="DataAdapterTypeName" length="255" sql-type="varchar" not-null="false"/>
      </property>
      <property name="PresenterTypeName" type="String">
         <column name="PresenterTypeName" length="255" sql-type="varchar" not-null="false"/>
      </property>
      <property name="TableName" type="String">
         <column name="TableName" length="255" sql-type="varchar" not-null="false"/>
      </property>
      <!-- many-to-one foreign key relationships -->
      <!-- end of many-to-one foreign keys -->
      <!--<bag name="StdProfileItemTitles" inverse="true" lazy="true" cascade="all-delete-orphan">
         <key column="ItemAdapterID"/>
         <one-to-many class="LightsCore.prf_StdProfileItemTitle, LightsTogether.Profiles.Data"/>
      </bag>-->
      <!--<bag name="ProfileItemTitles" inverse="true" lazy="true" cascade="all-delete-orphan">
         <key column="ItemAdapterID" />
         <one-to-many class="LightsCore.prf_ProfileItemTitle, LightsTogether.Profiles.Data"/>
      </bag>-->
   </class>
   <class name="LightsCore.prf_ProfileItemTitle, LT.Profiles.Data" table="prf.ProfileItemTitle">
      <id name="Id" type="Int32" unsaved-value="null">
         <column name="TitleID" length="4" sql-type="int" not-null="true" unique="true" index="PK_MemberProfileArea"/>
         <generator class="native" />
      </id>
      <property name="TitleName" type="String">
         <column name="TitleName" length="50" sql-type="varchar" not-null="true"/>
      </property>
      <property name="TitleLabelId" type="Int32">
         <column name="Title_LabelId" length="4" sql-type="int" not-null="false"/>
      </property>
      <property name="DescriptionLabelId" type="Int32">
         <column name="Description_LabelId" length="4" sql-type="int" not-null="false"/>
      </property>
      <property name="IsEnable" type="Boolean">
         <column name="IsEnable" length="1" sql-type="bit" not-null="true"/>
      </property>
      <property name="EditOn" type="DateTime">
         <column name="EditOn" length="4" sql-type="smalldatetime" not-null="true"/>
      </property>
      <property name="AddOn" type="DateTime">
         <column name="AddOn" length="4" sql-type="smalldatetime" not-null="true"/>
      </property>
      <property name="EditByID" type="Int32">
         <column name="EditByID" length="4" sql-type="int" not-null="true"/>
      </property>
      <property name="AddByID" type="Int32">
         <column name="AddByID" length="4" sql-type="int" not-null="true"/>
      </property>
      <!-- many-to-one foreign key relationships -->
      <!--<one-to-one name="prf_StdProfileItemTitle" class="LightsCore.prf_StdProfileItemTitle, LightsTogether.Profiles.Data">
         <column name="TitleID" length="4" sql-type="int" not-null="true" unique="true" index="PK_MemberProfileArea"/>
      </one-to-one>-->
      <many-to-one name="ProfileSection" class="LightsCore.prf_ProfileSection, LT.Profiles.Data">
         <column name="SectionID" length="4" sql-type="int" not-null="true"/>
      </many-to-one>
      <one-to-one name="ItemAdapter" class="LightsCore.prf_ItemAdapter, LightsTogether.Profiles.Data">
      </one-to-one>
      <!-- end of many-to-one foreign keys -->
      <!--<bag name="ProfileItemPicks" inverse="true" lazy="true" cascade="all-delete-orphan">
         <key column="TitleID"/>
         <one-to-many class="LightsCore.prf_ProfileItemPick, LightsTogether.Profiles.Data"/>
      </bag>-->
      <!--<bag name="ProfileItems" inverse="true" lazy="true" cascade="all-delete-orphan">
         <key column="TitleID"/>
         <one-to-many class="LightsCore.prf_ProfileItem, LightsTogether.Profiles.Data"/>
      </bag>-->
   </class>
   <class name="LightsCore.prf_ProfileSection, LightsTogether.Profiles.Data" table="prf.ProfileSection">
      <id name="Id" type="Int32" unsaved-value="null">
         <column name="SectionID" length="4" sql-type="int" not-null="true" unique="true" index="PK_MemProfileSection"/>
         <generator class="native" />
      </id>
      <property name="SectionName" type="String">
         <column name="SectionName" length="50" sql-type="varchar" not-null="true"/>
      </property>
      <property name="TitleLabelId" type="Int32">
         <column name="Title_LabelId" length="4" sql-type="int" not-null="false"/>
      </property>
      <property name="DescriptionLabelId" type="Int32">
         <column name="Description_LabelId" length="4" sql-type="int" not-null="false"/>
      </property>
      <property name="IsEnable" type="Boolean">
         <column name="IsEnable" length="1" sql-type="bit" not-null="true"/>
      </property>
      <property name="EditOn" type="DateTime">
         <column name="EditOn" length="4" sql-type="smalldatetime" not-null="true"/>
      </property>
      <property name="AddOn" type="DateTime">
         <column name="AddOn" length="4" sql-type="smalldatetime" not-null="true"/>
      </property>
      <property name="EditByID" type="Int32">
         <column name="EditByID" length="4" sql-type="int" not-null="true"/>
      </property>
      <property name="AddByID" type="Int32">
         <column name="AddByID" length="4" sql-type="int" not-null="true"/>
      </property>
      <!-- many-to-one foreign key relationships -->
      <!--<many-to-one name="prf_ProfileGroup" class="LightsCore.prf_ProfileGroup, LightsTogether.Profiles.Data">
         <column name="GroupID" length="4" sql-type="int" not-null="true"/>
      </many-to-one>-->
      <!-- end of many-to-one foreign keys -->
      <bag name="ProfileItemTitles" inverse="true" lazy="true" cascade="all-delete-orphan">
         <key column="SectionID"/>
         <one-to-many class="LightsCore.prf_ProfileItemTitle, LightsTogether.Profiles.Data"/>
      </bag>
   </class>
</hibernate-mapping>


(The mappings are all in separate files, but for ease of viewing I combined them for this post...)


Last edited by enewton76 on Tue Aug 14, 2007 11:45 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 11:09 am 
Newbie

Joined: Mon Aug 13, 2007 8:49 pm
Posts: 9
actually it appears that nhibernate is trying to assign an object[] into the closed-generic IList<prf_ProfileItemTitle>

update: it seems that the join isn't assigning the prf_ProfileSection instance into the ProfileSection property, but instead is pulling it out along side the prf_ProfileITemTitle...

I bet there's something I'm not doing exactly correct in the mapping.

Anybody got a tip? Break off some knowledge for this fool... ;-)


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.