Hi,
We have a web service which is supposed to return a list of objects, these objects are related to another object as ManyToMany.
The class definition are:
Code:
[NHibernate.Mapping.Attributes.Class(Table = "contacts")]
public class Contact
{
private int _iId;
private string _strTitle;
private string _strFirstName;
private string _strMiddleName;
private string _strLastName;
private ISet _collContactsGroups = new ListSet();
[NHibernate.Mapping.Attributes.Id(Name = "Id")]
[NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
public int Id
{
get
{
return _iId;
}
set
{
_iId = value;
}
}
[NHibernate.Mapping.Attributes.Property(Column = "title")]
public string Title
{
get
{
return _strTitle;
}
set
{
_strTitle = value;
}
}
[NHibernate.Mapping.Attributes.Property(Column = "firstName")]
public string FirstName
{
get
{
return _strFirstName;
}
set
{
_strFirstName = value;
}
}
[NHibernate.Mapping.Attributes.Property(Column = "middleName")]
public string MiddleName
{
get
{
return _strMiddleName;
}
set
{
_strMiddleName = value;
}
}
[NHibernate.Mapping.Attributes.Property(Column = "lastName")]
public string LastName
{
get
{
return _strLastName;
}
set
{
_strLastName = value;
}
}
[NHibernate.Mapping.Attributes.Set(1, Inverse = false, Lazy = true, Table = "contactsGroupsContatcs"),
NHibernate.Mapping.Attributes.Key(2, Column = "[contactId]"),
NHibernate.Mapping.Attributes.ManyToMany(3, Column = "[contactsGroupId]", ClassType = typeof(ContactsGroup)),
NHibernate.Mapping.Attributes.Cache(4, Usage = NHibernate.Mapping.Attributes.CacheUsage.ReadWrite)]
public ISet ContactsGroups
{
get
{
return _collContactsGroups;
}
set
{
_collContactsGroups = value;
}
}
}
Code:
[NHibernate.Mapping.Attributes.Class(Table = "contactsGroups")]
public class ContactsGroup
{
private int _iId;
private string _strName;
private Customer _objCustomer;
private DateTime _objExpire;
private IList _collContacts = new ArrayList();
private IList _collUsers = new ArrayList();
[NHibernate.Mapping.Attributes.Id(Name = "Id")]
[NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
public int Id
{
get
{
return _iId;
}
set
{
_iId = value;
}
}
[NHibernate.Mapping.Attributes.Property(Column = "name")]
public string Name
{
get
{
return _strName;
}
set
{
_strName = value;
}
}
[NHibernate.Mapping.Attributes.ManyToOne(Column = "customerId")]
public Customer Customer
{
get
{
return _objCustomer;
}
set
{
_objCustomer = value;
}
}
[NHibernate.Mapping.Attributes.Property(Column = "expire")]
public DateTime Expire
{
get
{
return _objExpire;
}
set
{
_objExpire = value;
}
}
[NHibernate.Mapping.Attributes.Bag(1, Inverse = true, Lazy = true, Table = "contactsGroupsContatcs", Cascade = NHibernate.Mapping.Attributes.CascadeStyle.SaveUpdate),
NHibernate.Mapping.Attributes.Key(2, Column = "[contactsGroupId]"),
NHibernate.Mapping.Attributes.ManyToMany(3, Column = "[contactId]", ClassType = typeof(Device))]
public IList Contacts
{
get
{
return _collContacts;
}
set
{
_collContacts = value;
}
}
[NHibernate.Mapping.Attributes.Bag(1, Inverse = true, Lazy = true, Table = "contactsGroupsUsers", Cascade = NHibernate.Mapping.Attributes.CascadeStyle.SaveUpdate),
NHibernate.Mapping.Attributes.Key(2, Column = "[contactsGroupId]"),
NHibernate.Mapping.Attributes.ManyToMany(3, Column = "[userId]", ClassType = typeof(User))]
public IList Users
{
get
{
return _collUsers;
}
set
{
_collUsers = value;
}
}
}
In the DB we have the class Contacts, ContactsGroups and ContactsGroupsContacts (linking table).
When we call the method on the web service we get:
Code:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> NHibernate.ADOException: could not initialize collection: [ZZZZZZZ.ZZZZZ.Contacts.DAO.Contact.ContactsGroups#1770] ---> System.IndexOutOfRangeException: [contactI1___]
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)
--- End of inner exception stack trace ---
at NHibernate.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.InitializeCollection(PersistentCollection collection, Boolean writing)
at NHibernate.Collection.PersistentCollection.ForceInitialization()
at NHibernate.Impl.SessionImpl.InitializeNonLazyCollections()
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
at NHibernate.Loader.CriteriaLoader.List(ISessionImplementor session)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)
at NHibernate.Impl.CriteriaImpl.List()
at ZZZZZZZ.ZZZZZ.Contacts.WebServices.ContactsWebService.GetContacts() in D:\Projects\Contacts Importer\Desktop Client\ContactsWebService\ContactsWebService.asmx.cs:line 131
--- End of inner exception stack trace ---
Does any one could help us with that?
We are using NHibernate 1.0.3
SQL Server 2005
Thanks very much