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