Hi,
I have an issue concerning mapping a collection.
I get the "collection was not an association" error while performing a "fetch all" operation.
Hibernate version: 1.2
Mapping documents:
I have a person class with the following mapping file:
<class name="Person" table="Person">
<id column="Id" name="Id" unsaved-value="00000000-0000-0000-0000-000000000000" access="nosetter.pascalcase-m-underscore">
<generator class="guid.comb" />
</id>
<bag access="field.pascalcase-m-underscore" name="Etiquettes" table="PersonEtiquette" lazy="true" cascade="all-delete-orphan">
<key column="PersonId"/>
<composite-element class="FilledEtiquette>
<many-to-one name="Etiquette" class="Etiquette" column="EtiquetteId" not-null="true"/>
<property name="Value" column="EtiquetteValue" type="String" length="255" not-null="false"/>
</composite-element>
</bag>
the class looks like this:
public abstract class Person
:Entity
{
private IList<FilledEtiquette> m_Etiquettes;
public Person()
: base()
{
m_Etiquettes = new List<FilledEtiquette>();
}
public IList<FilledEtiquette> Etiquettes
{
get
{
return new List<FilledEtiquette>(m_Etiquettes).AsReadOnly();
}
}
}
and the etiquette class looks like this:
public class FilledEtiquette
{
private Etiquette m_Etiquette;
private string m_Value;
public FilledEtiquette()
{
m_Etiquette = new Etiquette();
m_Value = string.Empty;
}
public virtual Etiquette Etiquette
{
get
{
return m_Etiquette;
}
set
{
m_Etiquette = value;
}
}
public virtual string Value
{
get
{
return m_Value;
}
set
{
m_Value = value;
}
}
}
Code used to fetch all persons
this is the code being used to get all of my person objects:
public class NhnPersonRepository
: NhnRepository, IPersonRepository
{
public NhnPersonRepository(HibernateTemplate template)
: base(template)
{
}
#region IPersonRepository Members
public IList<Person> FetchAll()
{
IList<Person> persons = Template.ExecuteFind<Person>(delegate(ISession session)
{
IQuery query = session.CreateQuery("select person from Person person");
return query.List<Person>();
});
persons;
}
#endregion
}
Full stack trace of any exception that occurs:
this is the error i get:
at NHibernate.Type.CollectionType.GetAssociatedClass(ISessionFactoryImplementor factory)
at NHibernate.Engine.Cascades.CascadeCollection(CascadingAction action, CascadeStyle style, CollectionType collectionType, IType elemType, Object child, CascadePoint cascadeVia, ISessionImplementor session, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, Object child, IType type, CascadingAction action, CascadeStyle style, CascadePoint cascadeTo, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, IEntityPersister persister, Object parent, CascadingAction action, CascadePoint cascadeTo, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, IEntityPersister persister, Object parent, CascadingAction action, CascadePoint cascadeTo)
at NHibernate.Impl.SessionImpl.PreFlushEntities()
at NHibernate.Impl.SessionImpl.FlushEverything()
at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet querySpaces)
at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results)
at NHibernate.Impl.SessionImpl.Find[T](String query, QueryParameters parameters)
at NHibernate.Impl.QueryImpl.List[T]()
at Softelligent.CRM.Customer.NhnRepositories.NhnPersonRepository.<FetchAll>b__0(ISession session)
at Spring.Data.NHibernate.Generic.ExecuteFindHibernateCallbackUsingDelegate`1.DoInHibernate(ISession session)
at Spring.Data.NHibernate.Generic.HibernateTemplate.ExecuteFind[T](IFindHibernateCallback`1 action, Boolean exposeNativeSession)
Can someone please help me with this one?
Grtz
|