Maybe at same place you used .net Task class instead of your class?

Gustavo.

On Thu, Apr 16, 2015 at 1:36 AM, brainbolt <[email protected]> wrote:

> I'm accustomed to seeing "No persister for:" errors when I don't have a
> class map defined for one of my classes, but not for an internal NHibernate
> class.
>
> I'm the getting this exception when I attempt to access the Tasks collection
> defined in the following relationship. It doesn't make a difference if the
> collection is eager or lazy loaded, except that if it is lazy loaded, the
> exception isn't thrown until I try to access the collection, so it seems
> that the exception is the result of NHibernate trying to query for the
> collection.
>
> I'm using the Fluent API for the mappings, but I've included the resulting
> hbm.xml file below.
>
> *TaskContainer* (base class)
>
> public abstract class TaskContainer : DomainObject{
>     public virtual IList<Task> Tasks { get; set; }}
>
> *Task*
>
> public class Task : TaskContainer{
>     public virtual TaskContainer TaskContainer { get; set; }
>     public virtual string Description { get; set; }
>
>     public virtual void AddChildTask(Task childTask)
>     {
>         if (Tasks == null)
>         {
>             Tasks = new List<Task>();
>         }
>
>         childTask.TaskContainer = this;
>         Tasks.Add(childTask);
>     }
>
>     public static Task Get(int id)
>     {
>         return Get<Task>(id);
>     }}
>
> *TaskMap*
>
> public class TaskMap : ClassMap<Task>{
>     public TaskMap()
>     {
>         Id(x => x.Id);
>         Map(x => x.Description);
>         ReferencesAny(x => x.TaskContainer)
>             .EntityIdentifierColumn("TaskContainer_Id")
>             .EntityTypeColumn("TaskContainerDiscriminator")
>             .IdentityType<int>()
>             .AddMetaValue<Task>("Task");
>         HasMany(x => x.Tasks)
>             .KeyColumns.Add("TaskContainer_Id", "TaskContainerDiscriminator")
>             .PropertyRef("TaskContainer")
>             .Not.LazyLoad();
>     }}
>
> *Exported hbm.xml map*
>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-cascade="all">
>   <class xmlns="urn:nhibernate-mapping-2.2" lazy="false" 
> name="CubeNet.Service.DomainObjects.Task, CubeNet.Service, Version=1.0.0.0, 
> Culture=neutral, PublicKeyToken=null" table="`Task`">
>     <id name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, 
> Culture=neutral, PublicKeyToken=b77a5c561934e089">
>       <column name="Id" />
>       <generator class="identity" />
>     </id>
>     <bag name="Tasks">
>       <key property-ref="TaskContainer">
>         <column name="TaskContainer_Id" />
>         <column name="TaskContainerDiscriminator" />
>       </key>
>       <one-to-many class="CubeNet.Service.DomainObjects.Task, 
> CubeNet.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
>     </bag>
>     <property name="Description" type="System.String, mscorlib, 
> Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
>       <column name="Description" />
>     </property>
>     <any id-type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, 
> PublicKeyToken=b77a5c561934e089" meta-type="System.String, mscorlib, 
> Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
> name="TaskContainer">
>       <meta-value value="Task" class="CubeNet.Service.DomainObjects.Task, 
> CubeNet.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
>       <column name="TaskContainerDiscriminator" />
>       <column name="TaskContainer_Id" />
>     </any>
>   </class></hibernate-mapping>
>
> Saving records with this configuration works as expected and produces the
> following table with these records
>
> Id  Description  TaskContainerDiscriminator  TaskContainer_Id--  -----------  
> --------------------------  ----------------1   Parent task  NULL             
>            NULL2   Child Task   Task                        1
>
> Retrieving the either record works, but the exception is thrown when
> attempting to access the collection of child records.
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to