-->
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: ArrayList property setter error
PostPosted: Mon Nov 21, 2005 5:31 pm 
Newbie

Joined: Wed Nov 16, 2005 2:40 pm
Posts: 19
Location: Palo Alto, CA
I am getting an error on an ArrayList property setter when NHibernate tries to persist my list. It passes in an object of type NHibernate.Collection.List, which causes my setter

Code:
      private ArrayList optionsList = new ArrayList();
      /// <summary>Option labels for corresponding choices.</summary>
      [System.Xml.Serialization.XmlIgnore]
      [NHibernate.Mapping.Attributes.List(Table="CategoricalOptions")]
         [NHibernate.Mapping.Attributes.Key(1, Column="QuestionID")]
         [NHibernate.Mapping.Attributes.Index(2, Column="QuestionSequence" )]
         [NHibernate.Mapping.Attributes.Element(3, Type="string", Column="Value", NotNull=true)]
      public ArrayList OptionsList
      {
         get { return this.optionsList; }
         set { this.optionsList = value; } //SetList( this.optionsList, value ); }
      }


to throw an exception:

Code:
The type NHibernate.Collection.List can not be assigned to a property of type System.Collections.ArrayList setter of CVAS.Primitives.QuestionSet.QuestionList
   at NHibernate.Property.BasicSetter.Set(Object target, Object value) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Property\BasicSetter.cs:line 53
   at Hibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj,  Object[] values) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Persister\AbstractEntityPersister.cs:line 170
   at NHibernate.Impl.SessionImpl.DoSave(Object theObj, Key key, IClassPersister  persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Impl\SessionImpl.cs:line 947
   at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IClassPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Impl\SessionImpl.cs:line
869
   at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Impl\SessionImpl.cs:line 764
   at NHibernate.Impl.SessionImpl.Save(Object obj) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Impl\SessionImpl.cs:line 710
   at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Impl\SessionImpl.cs:line 1536
   at Hibernate.Engine.ActionSaveUpdateClass.Cascade(ISessionImplementor session, Object child, Object anything) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Engine\Cascades.cs:line 169
   at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, Object child, IType type, CascadingAction action, CascadeStyle style, CascadePoint cascadeTo, Object anything) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Engine\Cascades.cs:line 559
   at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, IClassPersister persister, Object parent, CascadingAction action, CascadePoint cascadeTo, Object anything) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Engine\Cascades.cs:line 638
   at NHibernate.Impl.SessionImpl.DoSave(Object theObj, Key key, IClassPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Impl\SessionImpl.cs:line 906
   at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IClassPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Impl\SessionImpl.cs:line
869
   at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Impl\SessionImpl.cs:line 764
   at NHibernate.Impl.SessionImpl.Save(Object obj) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Impl\SessionImpl.cs:line 710
   at Test.Hibernate.TestFixture.CreateJob() in c:\projects\videoanalysis\temp\hibernate-test\test\testfixture\testfixture.cs:line 154
Object type cannot be converted to target type.
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.Reflection.MethodInfo.Invoke(Object obj, Object[] parameters)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
   at NHibernate.Property.BasicSetter.Set(Object target, Object value) in C:\projects\nhybernate.1.0.0.0\src\NHibernate\Property\BasicSetter.cs:line 42


My (relevant) mapping XML is

Code:
  <class name="CVAS.Primitives.QuestionSet, TestFixture" table="QuestionSets">
    <id name="ID">
      <generator class="native" />
    </id>
    <property name="Source" not-null="true" />
    <list name="QuestionList" cascade="save-update">
      <key column="QuestionSetID" />
      <index column="QuestionSetSequence" />
      <one-to-many class="CVAS.Primitives.Question, TestFixture" />
    </list>
  </class>


Any ideas?

Thanks!

Gene


Top
 Profile  
 
 Post subject: Re: ArrayList property setter error
PostPosted: Mon Nov 21, 2005 5:56 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
gene wrote:
Code:
      private ArrayList optionsList = new ArrayList();


Change to
Code:
private IList optionsList = new ArrayList();

Collections must be IList, IDictionary, or ISet.

http://nhibernate.sourceforge.net/nh-docs/html/collections.html


Top
 Profile  
 
 Post subject: Re: ArrayList property setter error
PostPosted: Mon Nov 21, 2005 8:54 pm 
Newbie

Joined: Wed Nov 16, 2005 2:40 pm
Posts: 19
Location: Palo Alto, CA
k-dub wrote:
Collections must be IList, IDictionary, or ISet.

http://nhibernate.sourceforge.net/nh-docs/html/collections.html



Duh! Thanks for your help!

Gene


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.