HasOne table-per-hierarchy abstract base

45 views
Skip to first unread message

mwpowellhtx

unread,
Aug 29, 2014, 5:41:53 PM8/29/14
to fluent-n...@googlegroups.com
Hello,

I've read a post on SO, but I have a case where I don't have a list so much as a HasOne.

One of my domain classes HasOne, but that one extends an abstract base class. I want the abstraction to persist to table-per-hierarchy in the usual sense, but how to persuade Fluent (and/or NHibernate) that it's okay to have the abstract base class.

In the meantime, I am receiving an exception building the configuration. AbstractScheduler is appropriately abstract, protected-parameterless-ctor, should not be instantiating it. However the mapping wants a public-parameterless-ctor.

Otherwise, I have mapped the derived schedulers in the usual SubclassMap sense with a discriminator value. Interested to know how to work past this sort of use case. I could set it up as a "default scheduler" in the base class, but that's not as interesting, and could lead to domain design confusion.

Thank you...

FluentNHibernate.Cfg.FluentConfigurationException was unhandled
  HResult=-2146233088
  Message=An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.


  Source=FluentNHibernate
  StackTrace:
       at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
       at Football.Data.Repository.Hibernate.SessionFactoryConfigurator.CreateFactory() in i:\Source\Kingdom Software\Football\Simulator\Football.Data\Repository\Hibernate\SessionFactoryConfigurator.cs:line 66
       at Football.Repository.SessionFactoryConfiguratorBase`1.get_Factory() in i:\Source\Kingdom Software\Football\Simulator\Football.Repository\SessionFactoryConfiguratorBase.cs:line 37
       at Football.Data.RepositoryExtensionMethods.GetRepositoryForSession[TConfigurator,TRepository](TConfigurator configurator, Func`2 getter, IInterceptor sessionLocalInterceptor) in i:\Source\Kingdom Software\Football\Simulator\Football.Data\Extensions\RepositoryExtensionMethods.cs:line 26
       at Football.Migrator.Program.Main(String[] args) in i:\Source\Kingdom Software\Football\Simulator\Football.Migrator\Program.cs:line 52
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: FluentNHibernate.Cfg.FluentConfigurationException
       HResult=-2146233088
       Message=An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.


       Source=FluentNHibernate
       StackTrace:
            at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
            at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
       InnerException: FluentNHibernate.MissingConstructorException
            HResult=-2146233088
            Message='Football.Data.Mappings.Schedulers.AbstractSchedulerMap, Football.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is missing a parameterless constructor.
            Source=FluentNHibernate
            StackTrace:
                 at FluentNHibernate.Utils.Extensions.InstantiateUsingParameterlessConstructor(Type type)
                 at FluentNHibernate.PersistenceModel.Add(Type type)
                 at FluentNHibernate.Utils.CollectionExtensions.Each[T](IEnumerable`1 enumerable, Action`1 each)
                 at FluentNHibernate.PersistenceModel.AddMappingsFromSource(ITypeSource source)
                 at FluentNHibernate.PersistenceModel.AddMappingsFromAssembly(Assembly assembly)
                 at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(PersistenceModel model)
                 at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
                 at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
            InnerException: 


Gleb Chermennov

unread,
Aug 30, 2014, 7:37:17 AM8/30/14
to fluent-n...@googlegroups.com
I see your point.
Can you post your code - classes, mappings and Fluent configuration - somewhere on the web (like gist/github) or just email them to me in case your project isn't opensource?
I'll investigate.

суббота, 30 августа 2014 г., 1:41:53 UTC+4 пользователь mwpowellhtx написал:

Michael Powell

unread,
Aug 30, 2014, 8:30:37 AM8/30/14
to fluent-n...@googlegroups.com
On Sat, Aug 30, 2014 at 6:37 AM, Gleb Chermennov
<thebitt...@gmail.com> wrote:
> I see your point.
> Can you post your code - classes, mappings and Fluent configuration -
> somewhere on the web (like gist/github) or just email them to me in case
> your project isn't opensource?
> I'll investigate.

Thanks for being available.

Upon closer examination, I overlooked a confusion between the ClassMap
and the SubclassMap. ClassMap for the abstract domain class was still
itself abstract. Should just be a concrete class with public
parameterless ctor itself. SubclassMap I extended from an abstract
base class serving the abstract domain model. The domain model itself
is fine as well.

Thank ye!
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Fluent NHibernate" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/fluent-nhibernate/7W9BJqh1VsY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> fluent-nhibern...@googlegroups.com.
> To post to this group, send email to fluent-n...@googlegroups.com.
> Visit this group at http://groups.google.com/group/fluent-nhibernate.
> For more options, visit https://groups.google.com/d/optout.

Michael Powell

unread,
Aug 30, 2014, 8:54:11 AM8/30/14
to fluent-n...@googlegroups.com
On Sat, Aug 30, 2014 at 7:30 AM, Michael Powell <mwpow...@gmail.com> wrote:
> On Sat, Aug 30, 2014 at 6:37 AM, Gleb Chermennov
> <thebitt...@gmail.com> wrote:
>> I see your point.
>> Can you post your code - classes, mappings and Fluent configuration -
>> somewhere on the web (like gist/github) or just email them to me in case
>> your project isn't opensource?
>> I'll investigate.
>
> Thanks for being available.
>
> Upon closer examination, I overlooked a confusion between the ClassMap
> and the SubclassMap. ClassMap for the abstract domain class was still
> itself abstract. Should just be a concrete class with public
> parameterless ctor itself. SubclassMap I extended from an abstract
> base class serving the abstract domain model. The domain model itself
> is fine as well.
>
> Thank ye!

I may have spoken too soon.

Every Schedule HasOne associated Scheduler, AbstractScheduler,
extending into SeasonScheduler, TournamentScheduler, and so on.

In the Schedule mapping:

HasOne(x => x.Scheduler)
.PropertyRef(r => r.Schedule)
.Cascade.All();

Unless Fluent and/or NHibernate is having a problem with the
abstraction, I fail to see how it does not find the property Schedule
referring to the Scheduler's parent.

Another possibility, is PropertyRef necessary? Or use References in
the child on the other side of the HasOne (or HasMany)?

Thank ye...
InnerException: NHibernate.MappingException
HResult=-2146232832
Message=property-ref [Parent] not found on entity
[Football.Models.Schedulers.AbstractScheduler]
Source=NHibernate
StackTrace:
at NHibernate.Mapping.PersistentClass.GetReferencedProperty(String
propertyPath)
at NHibernate.Cfg.Configuration.SecondPassCompile()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
InnerException: NHibernate.MappingException
HResult=-2146232832
Message=property [Parent] not found on entity
[Football.Models.Schedulers.AbstractScheduler]
Source=NHibernate
StackTrace:
at
NHibernate.Mapping.PersistentClass.GetRecursiveProperty(String
propertyPath, IEnumerable`1 iter)
at
NHibernate.Mapping.PersistentClass.GetReferencedProperty(String
propertyPath)
InnerException:

mustafa bal

unread,
Apr 27, 2015, 4:25:44 PM4/27/15
to fluent-n...@googlegroups.com

can you help me i have error Nhibernate that 

An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

but my project working my local machine but not host what can i do that problem 

Gleb Chermennov

unread,
Apr 28, 2015, 1:11:13 AM4/28/15
to fluent-n...@googlegroups.com
​What does InnerException say? What are you trying to do?​

--
You received this message because you are subscribed to a topic in the Google Groups "Fluent NHibernate" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fluent-nhibernate/7W9BJqh1VsY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fluent-nhibern...@googlegroups.com.
To post to this group, send email to fluent-n...@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/d/optout.



--
Yours faithfully, 
Gleb

mustafa bal

unread,
Apr 28, 2015, 2:48:48 AM4/28/15
to fluent-n...@googlegroups.com
İ fixed vs. Cache my local database connection, when i clear cache it is working. 

28 Nisan 2015 Salı tarihinde, Gleb Chermennov <thebitt...@gmail.com> yazdı:

Gleb Chermennov

unread,
Apr 28, 2015, 5:28:13 AM4/28/15
to fluent-n...@googlegroups.com
Sorry, I don't quite understand what you're talking about.
Reply all
Reply to author
Forward
0 new messages