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.  [ 6 posts ] 
Author Message
 Post subject: PLEASE! Many To Many problems
PostPosted: Mon Sep 03, 2007 10:23 am 
Newbie

Joined: Thu Jul 26, 2007 6:58 am
Posts: 19
Hi,

I am pretty new to ORM, so probably I am doing something really stupid.

The Exception I am getting is:

Code:
{"Error getting groups collection: Failed to lazily initialize a collection"}


When calling:

Code:
foreach (Group objGroup in objUser.GroupsCollection)
                {


The Stack is:

Code:
   at NHibernate.Collection.PersistentCollection.Initialize(Boolean writing)
   at NHibernate.Collection.PersistentCollection.Read()
   at NHibernate.Collection.Bag.GetEnumerator()
   at TestNHibernate.TestNHibernate.SetContacts() in D:\TestNHibernate\TestNHibernate\TestNHibernate\Form1.cs:line 103


The tables involved in this test are:
contacts (N) -> (1) groups
groups(N) -> (1) groupsType
users(N) -> (N) groups (usersGroups is the N-N table)

The DAO objects are:

Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;

using Iesi.Collections;

namespace DynamicDevices.SyncAPI.Contacts.DAO
{
    [NHibernate.Mapping.Attributes.Class(Table = "contacts")]
    public class Contact
    {
        private int _iId;
        private string _strTitle;
       
   //AROUND 100 other fields here (All String)

        private bool _bDeleted;

        private Group _objGroup;

        //private IList<ContactsGroup> _collContactsGroups = new List<ContactsGroup>();
       
        [NHibernate.Mapping.Attributes.Id(Name = "Id")]
        [NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
        public virtual int Id
        {
            get
            {
                return _iId;
            }
            set
            {
                _iId = value;
            }
        }
        [NHibernate.Mapping.Attributes.Property(Column = "title")]
        public virtual string Title
        {
            get
            {
                return _strTitle;
            }
            set
            {
                _strTitle = value;
            }
        }
       
        //AROUND 100 other attributes here (All String)


        [NHibernate.Mapping.Attributes.Property(Column = "deleted")]
        public virtual bool Deleted
        {
            get
            {
                return _bDeleted;
            }
            set
            {
                _bDeleted = value;
            }
        }

        [NHibernate.Mapping.Attributes.ManyToOne(Column = "groupId")]
        public virtual Group Group
        {
            get
            {
                return _objGroup;
            }
            set
            {
                _objGroup = value;
            }
        }
                                   
   }
}


Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;

namespace DynamicDevices.SyncAPI.Contacts.DAO
{
    [NHibernate.Mapping.Attributes.Class(Table = "groups")]
    public class Group
    {
        private int _iId;
        private string _strName;
        private GroupType _objGroupType;
        private IList _collUsers = new ArrayList();


        [NHibernate.Mapping.Attributes.Id(Name = "Id")]
        [NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
        public virtual int Id
        {
            get
            {
                return _iId;
            }
            set
            {
                _iId = value;
            }
        }

        [NHibernate.Mapping.Attributes.Property(Column = "name")]
        public virtual string Name
        {
            get
            {
                return _strName;
            }
            set
            {
                _strName = value;
            }
        }
       
        [NHibernate.Mapping.Attributes.ManyToOne(Column = "groupTypeId")]
        public virtual GroupType Type
        {
          get
          {
              return _objGroupType;
          }
          set
          {
              _objGroupType = value;
          }
        }

 
        [NHibernate.Mapping.Attributes.Bag(1, Inverse = false, Lazy = true, Table = "usersGroup", Cascade = NHibernate.Mapping.Attributes.CascadeStyle.SaveUpdate),
        NHibernate.Mapping.Attributes.Key(2, Column = "[groupId]"),
        NHibernate.Mapping.Attributes.ManyToMany(3, Column = "[userId]", ClassType = typeof(User))]
        public virtual IList UsersCollection
        {
          get
          {
              return _collUsers;
          }
          set
          {
              _collUsers = value;
          }
        }
    }
}



Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;

namespace DynamicDevices.SyncAPI.Contacts.DAO
{
    [NHibernate.Mapping.Attributes.Class(Table = "groupsType")]
    public class GroupType
    {
        private int _iId;
        private string _strName;
        private bool _bDefault = false;
       
        [NHibernate.Mapping.Attributes.Id(Name = "Id")]
        [NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
        public virtual int Id
        {
            get
            {
                return _iId;
            }
            set
            {
                _iId = value;
            }
        }

        [NHibernate.Mapping.Attributes.Property(Column = "name")]
        public virtual string Name
        {
            get
            {
                return _strName;
            }
            set
            {
                _strName = value;
            }
        }

        [NHibernate.Mapping.Attributes.Property(Column = "isDefault")]
        public virtual bool Default
        {
            get
            {
                return _bDefault;
            }
            set
            {
                _bDefault = value;
            }
        }

    }
}



Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using Iesi.Collections;

namespace DynamicDevices.SyncAPI.Contacts.DAO
{
    [NHibernate.Mapping.Attributes.Class(Table = "users")]
    public class User
    {
        private int _iId;
        private string _strLogon;
        private string _strPassword;
        private string _strEmail;

        private bool _bDeleted;
     
        private IList _collGroups = new ArrayList();

        [NHibernate.Mapping.Attributes.Id(Name = "Id")]
        [NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
        public virtual int Id
        {
            get
            {
                return _iId;
            }
            set
            {
                _iId = value;
            }
        }

        [NHibernate.Mapping.Attributes.Property(Column = "logon")]
        public virtual string Logon
        {
            get
            {
                return _strLogon;
            }
            set
            {
                _strLogon = value;
            }
        }

        [NHibernate.Mapping.Attributes.Property(Column = "password")]
        public virtual string Password
        {
            get
            {
                return _strPassword;
            }
            set
            {
                _strPassword = value;
            }
        }

        [NHibernate.Mapping.Attributes.Property(Column = "email")]
        public virtual string Email
        {
            get
            {
                return _strEmail;
            }
            set
            {
                _strEmail = value;
            }
        }

        [NHibernate.Mapping.Attributes.Property(Column = "deleted")]
        public virtual bool Deleted
        {
            get
            {
                return _bDeleted;
            }
            set
            {
                _bDeleted = value;
            }
        }
       
        [NHibernate.Mapping.Attributes.Bag(1, Inverse = true, Lazy = true, Table = "usersGroup", Cascade = NHibernate.Mapping.Attributes.CascadeStyle.SaveUpdate),
        NHibernate.Mapping.Attributes.Key(2, Column = "[userId]"),
        NHibernate.Mapping.Attributes.ManyToMany(3, Column = "[groupId]", ClassType = typeof(Group))]
        public virtual IList GroupsCollection
        {
            get
            {
                return _collGroups;
            }
            set
            {
                _collGroups = value;
            }
        }

    }
}


Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using log4net;

using NHibernate;
using NHibernate.Cfg;

using DynamicDevices.SyncAPI.Contacts.DAO;

namespace TestNHibernate
{
    public partial class TestNHibernate : Form
    {

        private ILog _objLogger = log4net.LogManager.GetLogger(typeof(TestNHibernate));

        private Configuration _cfg;

        private ISession _objSession = null;

        List<Contact> _collContacts = new List<Contact>();

        public TestNHibernate()
        {
            InitializeComponent();

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("log4net.config"));

            _objLogger.Info("Started ContactsWebService");

            _cfg = new Configuration();
           
            NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true;
           
            System.IO.MemoryStream objStream = new System.IO.MemoryStream();
            NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(objStream, System.Reflection.Assembly.GetAssembly(typeof(Contact)));
            objStream.Position = 0;
            _cfg.AddInputStream(objStream);
            objStream.Close();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            ISessionFactory objFactory = _cfg.BuildSessionFactory();
            _objSession = objFactory.OpenSession();

            GetContacts();

            SetContacts();

            _objSession.Close();
        }

        private void GetContacts()
        {
            System.Collections.IList objList = null;           

            NHibernate.Expression.ICriterion lhs = NHibernate.Expression.Expression.Eq("Deleted", false);
            NHibernate.Expression.ICriterion rhs = NHibernate.Expression.Expression.IsNull("Deleted");

            objList = _objSession.CreateCriteria(typeof(Contact))
                .Add(NHibernate.Expression.Expression.Or(lhs, rhs))
                .List();

            _collContacts.Clear();
            foreach (object o in objList)
                _collContacts.Add((Contact)o);

            _objLogger.Debug("Total Contacts:" + objList.Count);

        }

        private void SetContacts()
        {
            ITransaction objTransaction = _objSession.BeginTransaction();

            System.Collections.IList objList = null;

            objList = _objSession.CreateCriteria(typeof(User))
                .Add(NHibernate.Expression.Expression.Eq("Logon", "demo"))
                .List();

            if (objList.Count < 1)
                return;

            User objUser = (User)objList[0];

            if (objUser == null)
                throw new Exception("Not logged on");
                       
            string strMessage = "";
            Group objDefaultGroup = null;

            try
            {               
                foreach (Group objGroup in objUser.GroupsCollection)
                {
                    if (objGroup.Type.Default)
                    {
                        objDefaultGroup = objGroup;
                        break;
                    }
                }
            }

            catch (Exception ex)
            {
                throw new Exception("Error getting groups collection: " + ex.Message);
            }

            if (objDefaultGroup == null)
                throw new Exception("The user does not have a default group");                         

            // CHECK: How to make sure that only the right contacts are updated ?
            foreach (Contact c in _collContacts)
            {
                // Ensure this is set correctly !
                c.Group = objDefaultGroup;               
                _objSession.SaveOrUpdate(c);
            }

            objTransaction.Commit();

        }
    }
}


I don't know what is wrong!!
I spent half a day trying to find an answer for that! No joy though! :(

Could anyone help me please?

Thanks
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 11:55 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
The default answer is to make sure you aren't initializing within the same session, but it doesn't look like you are closing your session improperly, so there must be something else going on.

A couple of notes: do not rebuild your session factory with each button click. A session factory should be built once per application instance (very expensive operation). Also, when you wrap an exception, make sure use the Exception( string, Exception ) ctor, and set the inner exception.

Try the latter and see if you can get any more detail from Exception.ToString().


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 1:31 pm 
Newbie

Joined: Thu Jul 26, 2007 6:58 am
Posts: 19
Hi,

Thanks for your answer.
I am logging everything now and the exception from NHibernate is (the part which I think matters):

Code:
2007-09-04 18:11:39,312 [4864  ] DEBUG ((null)           ) ((null)) initializing class SessionFactoryObjectFactory
2007-09-04 18:11:39,312 [4864  ] DEBUG ((null)           ) ((null)) registered: e721dd9a84e74d39984c22d47a1d806f(unnamed)
2007-09-04 18:11:39,312 [4864  ] INFO  ((null)           ) ((null)) no name configured
2007-09-04 18:11:39,312 [4864  ] DEBUG ((null)           ) ((null)) Instantiated session factory
2007-09-04 18:11:39,343 [4864  ] DEBUG ((null)           ) ((null)) opened session
2007-09-04 18:11:39,390 [4864  ] DEBUG ((null)           ) ((null)) The initial capacity was set too low at: 8 for the SelectSqlBuilder that needed a capacity of: 14 for the table users this
2007-09-04 18:11:39,406 [4864  ] DEBUG ((null)           ) ((null)) flushing session
2007-09-04 18:11:39,421 [4864  ] DEBUG ((null)           ) ((null)) Flushing entities and processing referenced collections
2007-09-04 18:11:39,421 [4864  ] DEBUG ((null)           ) ((null)) Processing unreferenced collections
2007-09-04 18:11:39,421 [4864  ] DEBUG ((null)           ) ((null)) scheduling collection removes/(re)creates/updates
2007-09-04 18:11:39,421 [4864  ] DEBUG ((null)           ) ((null)) Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
2007-09-04 18:11:39,421 [4864  ] DEBUG ((null)           ) ((null)) Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2007-09-04 18:11:39,437 [4864  ] DEBUG ((null)           ) ((null)) dont need to execute flush
2007-09-04 18:11:39,515 [4864  ] DEBUG ((null)           ) ((null)) Opened new IDbCommand, open IDbCommands :1
2007-09-04 18:11:39,515 [4864  ] DEBUG ((null)           ) ((null)) Building an IDbCommand object for the SqlString: SELECT this.Id as Id0_, this.email as email0_, this.logon as logon0_, this.deleted as deleted0_, this.password as password0_ FROM users this WHERE (this.logon = :this.logon and this.password = :this.password)
2007-09-04 18:11:39,515 [4864  ] DEBUG ((null)           ) ((null)) binding 'demo' to parameter: 0
2007-09-04 18:11:39,515 [4864  ] DEBUG ((null)           ) ((null)) binding 'demo' to parameter: 1
2007-09-04 18:11:39,515 [4864  ] INFO  ((null)           ) ((null)) SELECT this.Id as Id0_, this.email as email0_, this.logon as logon0_, this.deleted as deleted0_, this.password as password0_ FROM users this WHERE (this.logon = @p0 and this.password = @p1)
2007-09-04 18:11:39,531 [4864  ] DEBUG ((null)           ) ((null)) SELECT this.Id as Id0_, this.email as email0_, this.logon as logon0_, this.deleted as deleted0_, this.password as password0_ FROM users this WHERE (this.logon = @p0 and this.password = @p1)
2007-09-04 18:11:39,531 [4864  ] DEBUG ((null)           ) ((null)) @p0 = 'demo'
2007-09-04 18:11:39,531 [4864  ] DEBUG ((null)           ) ((null)) @p1 = 'demo'
2007-09-04 18:11:39,531 [4864  ] DEBUG ((null)           ) ((null)) Obtaining IDbConnection from Driver
2007-09-04 18:11:39,796 [4864  ] DEBUG ((null)           ) ((null)) Opened Reader, open Readers :1
2007-09-04 18:11:39,796 [4864  ] DEBUG ((null)           ) ((null)) processing result set
2007-09-04 18:11:39,812 [4864  ] DEBUG ((null)           ) ((null)) returning '1' as column: Id0_
2007-09-04 18:11:39,812 [4864  ] DEBUG ((null)           ) ((null)) result row: 1
2007-09-04 18:11:39,828 [4864  ] DEBUG ((null)           ) ((null)) Initializing object from DataReader: 1
2007-09-04 18:11:39,843 [4864  ] DEBUG ((null)           ) ((null)) Hydrating entity: Test.SyncAPI.Contacts.DAO.User#1
2007-09-04 18:11:39,843 [4864  ] DEBUG ((null)           ) ((null)) returning '[email protected]' as column: email0_
2007-09-04 18:11:39,843 [4864  ] DEBUG ((null)           ) ((null)) returning 'demo' as column: logon0_
2007-09-04 18:11:39,843 [4864  ] DEBUG ((null)           ) ((null)) returning 'False' as column: deleted0_
2007-09-04 18:11:39,843 [4864  ] DEBUG ((null)           ) ((null)) returning 'demo' as column: password0_
2007-09-04 18:11:39,843 [4864  ] DEBUG ((null)           ) ((null)) done processing result set (1 rows)
2007-09-04 18:11:39,843 [4864  ] DEBUG ((null)           ) ((null)) running NHybridDataReader.Dispose()
2007-09-04 18:11:39,859 [4864  ] DEBUG ((null)           ) ((null)) Closed Reader, open Readers :0
2007-09-04 18:11:39,859 [4864  ] DEBUG ((null)           ) ((null)) Closed IDbCommand, open IDbCommands :0
2007-09-04 18:11:39,859 [4864  ] DEBUG ((null)           ) ((null)) total objects hydrated: 1
2007-09-04 18:11:39,859 [4864  ] DEBUG ((null)           ) ((null)) resolving associations for: [Test.SyncAPI.Contacts.DAO.User#1]
2007-09-04 18:11:39,875 [4864  ] DEBUG ((null)           ) ((null)) creating collection wrapper:[Test.SyncAPI.Contacts.DAO.User.GroupsCollection#1]
2007-09-04 18:11:39,890 [4864  ] DEBUG ((null)           ) ((null)) done materializing entity [Test.SyncAPI.Contacts.DAO.User#1]
2007-09-04 18:11:39,890 [4864  ] DEBUG ((null)           ) ((null)) initializing non-lazy collections
2007-09-04 18:11:39,890 [4864  ] DEBUG ((null)           ) ((null)) initializing collection [Test.SyncAPI.Contacts.DAO.User.GroupsCollection#1]
2007-09-04 18:11:39,890 [4864  ] DEBUG ((null)           ) ((null)) checking second-level cache
2007-09-04 18:11:39,890 [4864  ] DEBUG ((null)           ) ((null)) collection not cached
2007-09-04 18:11:39,890 [4864  ] DEBUG ((null)           ) ((null)) Opened new IDbCommand, open IDbCommands :1
2007-09-04 18:11:39,890 [4864  ] DEBUG ((null)           ) ((null)) Building an IDbCommand object for the SqlString: SELECT groupscoll0_.[userId] as [userId__], groupscoll0_.[groupId] as [groupId__], group1_.Id as Id0_, group1_.name as name0_, group1_.groupTypeId as groupTyp3_0_, grouptype2_.Id as Id1_, grouptype2_.name as name1_, grouptype2_.isDefault as isDefault1_ FROM usersGroup groupscoll0_ inner join groups group1_ on groupscoll0_.[groupId]=group1_.Id left outer join groupsType grouptype2_ on group1_.groupTypeId=grouptype2_.Id WHERE groupscoll0_.[userId]=:[userId]
2007-09-04 18:11:39,890 [4864  ] DEBUG ((null)           ) ((null)) binding '1' to parameter: 0
2007-09-04 18:11:39,890 [4864  ] INFO  ((null)           ) ((null)) SELECT groupscoll0_.[userId] as [userId__], groupscoll0_.[groupId] as [groupId__], group1_.Id as Id0_, group1_.name as name0_, group1_.groupTypeId as groupTyp3_0_, grouptype2_.Id as Id1_, grouptype2_.name as name1_, grouptype2_.isDefault as isDefault1_ FROM usersGroup groupscoll0_ inner join groups group1_ on groupscoll0_.[groupId]=group1_.Id left outer join groupsType grouptype2_ on group1_.groupTypeId=grouptype2_.Id WHERE groupscoll0_.[userId]=@p0
2007-09-04 18:11:39,890 [4864  ] DEBUG ((null)           ) ((null)) SELECT groupscoll0_.[userId] as [userId__], groupscoll0_.[groupId] as [groupId__], group1_.Id as Id0_, group1_.name as name0_, group1_.groupTypeId as groupTyp3_0_, grouptype2_.Id as Id1_, grouptype2_.name as name1_, grouptype2_.isDefault as isDefault1_ FROM usersGroup groupscoll0_ inner join groups group1_ on groupscoll0_.[groupId]=group1_.Id left outer join groupsType grouptype2_ on group1_.groupTypeId=grouptype2_.Id WHERE groupscoll0_.[userId]=@p0
2007-09-04 18:11:39,890 [4864  ] DEBUG ((null)           ) ((null)) @p0 = '1'
2007-09-04 18:11:39,906 [4864  ] DEBUG ((null)           ) ((null)) Opened Reader, open Readers :1
2007-09-04 18:11:39,906 [4864  ] DEBUG ((null)           ) ((null)) result set contains (possibly empty) collection: [Test.SyncAPI.Contacts.DAO.User.GroupsCollection#1]
2007-09-04 18:11:39,906 [4864  ] DEBUG ((null)           ) ((null)) uninitialized collection: initializing
2007-09-04 18:11:39,906 [4864  ] DEBUG ((null)           ) ((null)) processing result set
2007-09-04 18:11:39,906 [4864  ] DEBUG ((null)           ) ((null)) returning '5' as column: Id0_
2007-09-04 18:11:39,906 [4864  ] DEBUG ((null)           ) ((null)) returning '1' as column: Id1_
2007-09-04 18:11:39,906 [4864  ] DEBUG ((null)           ) ((null)) result row: 5, 1
2007-09-04 18:11:39,906 [4864  ] DEBUG ((null)           ) ((null)) Initializing object from DataReader: 5
2007-09-04 18:11:39,906 [4864  ] DEBUG ((null)           ) ((null)) Hydrating entity: Test.SyncAPI.Contacts.DAO.Group#5
2007-09-04 18:11:39,906 [4864  ] DEBUG ((null)           ) ((null)) returning 'demo' as column: name0_
2007-09-04 18:11:39,921 [4864  ] DEBUG ((null)           ) ((null)) returning '1' as column: groupTyp3_0_
2007-09-04 18:11:39,921 [4864  ] DEBUG ((null)           ) ((null)) Initializing object from DataReader: 1
2007-09-04 18:11:39,921 [4864  ] DEBUG ((null)           ) ((null)) Hydrating entity: Test.SyncAPI.Contacts.DAO.GroupType#1
2007-09-04 18:11:39,921 [4864  ] DEBUG ((null)           ) ((null)) returning 'Private                                           ' as column: name1_
2007-09-04 18:11:39,921 [4864  ] DEBUG ((null)           ) ((null)) returning 'True' as column: isDefault1_
2007-09-04 18:11:39,921 [4864  ] DEBUG ((null)           ) ((null)) SQL Exception
System.IndexOutOfRangeException: [userId__]
   at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
   at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
   at NHibernate.Driver.NHybridDataReader.GetOrdinal(String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
   at NHibernate.Collection.AbstractCollectionPersister.ReadKey(IDataReader dr, ISessionImplementor session)
   at NHibernate.Loader.Loader.ReadCollectionElement(Object optionalOwner, Object optionalKey, IDataReader rs, ISessionImplementor session)
   at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, IList hydratedObjects, Object optionalObject, Object optionalId, Key[] keys, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
2007-09-04 18:11:39,937 [4864  ] WARN  ((null)           ) ((null)) System.IndexOutOfRangeException: [userId__]
   at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
   at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
   at NHibernate.Driver.NHybridDataReader.GetOrdinal(String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
   at NHibernate.Collection.AbstractCollectionPersister.ReadKey(IDataReader dr, ISessionImplementor session)
   at NHibernate.Loader.Loader.ReadCollectionElement(Object optionalOwner, Object optionalKey, IDataReader rs, ISessionImplementor session)
   at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, IList hydratedObjects, Object optionalObject, Object optionalId, Key[] keys, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
2007-09-04 18:11:39,937 [4864  ] ERROR ((null)           ) ((null)) [userId__]
2007-09-04 18:11:39,937 [4864  ] DEBUG ((null)           ) ((null)) running NHybridDataReader.Dispose()
2007-09-04 18:11:39,937 [4864  ] DEBUG ((null)           ) ((null)) Closed Reader, open Readers :0
2007-09-04 18:11:39,937 [4864  ] DEBUG ((null)           ) ((null)) Closed IDbCommand, open IDbCommands :0
2007-09-04 18:11:39,937 [4864  ] DEBUG ((null)           ) ((null)) could not initialize collection: [Test.SyncAPI.Contacts.DAO.User.GroupsCollection#1]
System.IndexOutOfRangeException: [userId__]
   at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
   at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
   at NHibernate.Driver.NHybridDataReader.GetOrdinal(String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
   at NHibernate.Collection.AbstractCollectionPersister.ReadKey(IDataReader dr, ISessionImplementor session)
   at NHibernate.Loader.Loader.ReadCollectionElement(Object optionalOwner, Object optionalKey, IDataReader rs, ISessionImplementor session)
   at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, IList hydratedObjects, Object optionalObject, Object optionalId, Key[] keys, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
   at NHibernate.Loader.CollectionLoader.Initialize(Object id, ISessionImplementor session)
   at NHibernate.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session)
2007-09-04 18:11:39,937 [4864  ] WARN  ((null)           ) ((null)) System.IndexOutOfRangeException: [userId__]
   at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
   at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
   at NHibernate.Driver.NHybridDataReader.GetOrdinal(String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
   at NHibernate.Collection.AbstractCollectionPersister.ReadKey(IDataReader dr, ISessionImplementor session)
   at NHibernate.Loader.Loader.ReadCollectionElement(Object optionalOwner, Object optionalKey, IDataReader rs, ISessionImplementor session)
   at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, IList hydratedObjects, Object optionalObject, Object optionalId, Key[] keys, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
   at NHibernate.Loader.CollectionLoader.Initialize(Object id, ISessionImplementor session)
   at NHibernate.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session)
2007-09-04 18:11:39,937 [4864  ] ERROR ((null)           ) ((null)) [userId__]


The last executed query (it works if I run it in the SSMS) is:

Code:
exec sp_executesql N'SELECT groupscoll0_.[userId] as [userId__], groupscoll0_.[groupId] as [groupId__], group1_.Id as Id0_, group1_.name as name0_, group1_.groupTypeId as groupTyp3_0_,
grouptype2_.Id as Id1_, grouptype2_.name as name1_, grouptype2_.isDefault as isDefault1_ FROM usersGroup groupscoll0_ inner join groups group1_ on groupscoll0_.[groupId]=group1_.Id left outer
join groupsType grouptype2_ on group1_.groupTypeId=grouptype2_.Id WHERE groupscoll0_.[userId]=@p0',N'@p0 int',@p0=1


I can't believe that's so painful! It should be easy as I am not doing anything complicated.

Anyone else with any good tip?

Cheers


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 6:01 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Drop the brackets around the names in your mapping attributes. I think it may be confusing something.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 05, 2007 5:36 am 
Newbie

Joined: Thu Jul 26, 2007 6:58 am
Posts: 19
Hi,

I can't remove the brackets as they are part of the sintax for attributes. I don't think that is the problem though!

Really, how annoying is that!

Thanks for trying to help! :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 05, 2007 8:26 am 
Newbie

Joined: Thu Jul 26, 2007 6:58 am
Posts: 19
Thanks Guys,

I've updated the NHibernate from 1.0.4 to 1.2 and now it is working.

Cheers


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.