Hibernate version: Nhibernate 1.0.2.0
Mapping documents:
Code:
<class name="PFC_Portal.DataModel.Subscription, DataModel" table="Subscriptions">
<id name="Id" column="SubscriptionId" type="Int32">
<generator class="identity"/>
</id>
<property name="Status" column="StatusId" type="Int32" />
<array name="Service" table="SubscriptionServices">
<key column="SubscriptionId" />
<index column="I" />
<many-to-many column="SubscriptionServiceId" class="PFC_Portal.DataModel.Service, DataModel" />
</array>
<joined-subclass name="PFC_Portal.DataModel.SubscriptionByCredits, DataModel" table="SubscriptionsByCredits" >
<key column="SubscriptionId"/>
<property name="Credits" column="Credits" type="Int32" />
<property name="UserId" column="UserId" type="Int32" not-null="true"/>
</joined-subclass>
<joined-subclass name="PFC_Portal.DataModel.SubscriptionByTime, DataModel" table="SubscriptionsByTime">
<key column="SubscriptionId"/>
<property name="BeginDate" column="BeginDate" type="DateTime" />
<property name="EndDate" column="EndDate" type="DateTime" />
<property name="UserId" column="UserId" type="Int32" not-null="true"/>
</joined-subclass>
</class>
<class name="PFC_Portal.DataModel.User, DataModel" table="Users">
<id name="Id" type="Int32" column="UserId">
<generator class="identity"/>
</id>
<one-to-one name="SubscriptionsByCredits" class="PFC_Portal.DataModel.SubscriptionByCredits, DataModel" property-ref="UserId" cascade="all" />
<array name="SubscriptionsByTime">
<key column="UserId"/>
<index column="I" type="Int32"/>
<one-to-many class="PFC_Portal.DataModel.SubscriptionByTime, DataModel"/>
</array>
<property name="Name" column="Name" type="String" />
<property name="Address" column="Address" type="String" />
<property name="Password" column="Password" type="String" />
<property name="Login" column="Login" type="String" />
<property name="MobileNumber" column="MobileNumber" type="String" />
<property name="PhoneNumber" column="PhoneNumber" type="String" />
<array name="Roles" table="UsersRoles">
<key column="UserId" />
<index column="I" />
<many-to-many column="RoleId" class="PFC_Portal.DataModel.Role, DataModel" />
</array>
</class>
Code between sessionFactory.openSession() and session.close():
ISession session = AccessBD.openSession();
ITransaction tx = session.BeginTransaction();
IList users = session.CreateCriteria(typeof(User)).List();
tx.Commit();
session.Close();
return users;
Full stack trace of any exception that occurs:
null index column for collection: PFC_Portal.DataModel.User.SubscriptionsByTime
" at NHibernate.Collection.AbstractCollectionPersister.ReadIndex(IDataReader rs, ISessionImplementor session)\r\n at NHibernate.Collection.ArrayHolder.ReadFrom(IDataReader rs, ICollectionPersister persister, Object owner)\r\n at NHibernate.Loader.Loader.ReadCollectionElement(Object optionalOwner, Object optionalKey, IDataReader rs, ISessionImplementor session)\r\n at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, IList hydratedObjects, Object optionalObject, Object optionalId, Key[] keys, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object[] ids, IType[] types)\r\n at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type)\r\n at NHibernate.Loader.OneToManyLoader.Initialize(Object id, ISessionImplementor session)\r\n at NHibernate.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session)\r\n at NHibernate.Impl.SessionImpl.InitializeCollection(PersistentCollection collection, Boolean writing)\r\n at NHibernate.Impl.SessionImpl.GetCollection(String role, Object id, Object owner)\r\n at NHibernate.Type.PersistentCollectionType.ResolveIdentifier(Object value, ISessionImplementor session, Object owner)\r\n at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)\r\n at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)\r\n at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)\r\n at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)\r\n at NHibernate.Loader.CriteriaLoader.List(ISessionImplementor session)\r\n at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)\r\n at NHibernate.Impl.CriteriaImpl.List()\r\n at PFC_Portal.SR.BusinessLayer.UsersManager.getAllUsers() in D:\\ModelData_NHibernate\\SRModel\\SRBusinessLayer\\UsersManager.cs:line 132\r\n at PFC_Portal.SR.Presentation.Menu.buttonListAllUsers_Click(Object sender, EventArgs e) in D:\\ModelData_NHibernate\\SRModel\\SRPresentation\\Menu.cs:line 298\r\n at System.Windows.Forms.Control.OnClick(EventArgs e)\r\n at System.Windows.Forms.Button.OnClick(EventArgs e)\r\n at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)\r\n at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n at System.Windows.Forms.Control.WndProc(Message& m)\r\n at System.Windows.Forms.ButtonBase.WndProc(Message& m)\r\n at System.Windows.Forms.Button.WndProc(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run(Form mainForm)\r\n at PFC_Portal.SR.Presentation.Program.Main(String[] args) in D:\\ModelData_NHibernate\\SRModel\\SRPresentation\\Program.cs:line 18\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"
Name and version of the database you are using:
SQL Server 2005
I am using arrays but when i use with the one-to-many clause i can put data correctly, but i am unable get all users. Why is this hapenning? What is the use of the index in the arrays? Where should they be mapped to???
Thank you.