I did a bit more investigation after learning that the Castle proxy
factory factory is used by default in FNH. When I removed any attempt
to set this myself, that particular problem went away. However, that
exposed a different error, one dealing with a particular ClassMap,
that read "Could not format discriminator value to SQL string of
entity Campaign." I was a bit surprised, because my subclass
discrimination had been working for quite a while. The method call
looked like this:
DiscriminateSubClassesOnColumn<int>("intCampaignTypeID")
.SubClass<InspectionCampaign>(1, x => {} )
.SubClass<OBPCampaign>(2, x=> {});
After some searching about problems with the
DiscriminateSubClassesOnColumn method, I found a couple of instances
where people seemed to be having similar problems (http://
stackoverflow.com/questions/326174/nhibernate-mapping-with-a-class-
hierarchy-whose-base-class-is-abstract-and-the-di and
https://forum.hibernate.org/viewtopic.php?t=974225).
It turns out that when I add a "default" discriminator value to the
method call, everything's hunky dory.
DiscriminateSubClassesOnColumn<int>("intCampaignTypeID", -1)
.SubClass<InspectionCampaign>(1, x => {} )
.SubClass<OBPCampaign>(2, x=> { });
This bothers me a bit, though, because this "default" value doesn't
really exist. All of the values in the database are either 1 or 2,
and the Campaign base class is abstract anyway, so I don't want
NHibernate trying to create one in any case.
Was there a recent change that made this default value necessary? As
I said, the original method call without the default had been working
for a while.
Thanks for all your responses!
On Jul 21, 2:19 pm, James Gregory <[email protected]> wrote:
> You most definitely should not have to do that.
>
> On Tue, Jul 21, 2009 at 8:05 PM, Mikael Henriksson
> <[email protected]>wrote:
>
>
>
> > This is the only way I could get it working.
> > 1.Create a dictionary with all the required settings. For some reason
> > Fluent does not set these no matter how I try.
> > 2. When you configure nhibernate
> > (fluentConfig.BuildConfiguration().SetProperties(DICTIONARY) you need to
> > supply this dictionary.
>
> > IDictionary<string, string> properties =
> > new<http://www.google.com/search?q=new+msdn.microsoft.com>Dictionary
> > <string, string>();
> > properties.Add("proxyfactory.factory_class",
> > "NHibernate.ByteCode.Castle.ProxyFactoryFactory,
> > NHibernate.ByteCode.Castle");
> > properties.Add("dialect", "NHibernate.Dialect.SQLite");
> > properties.Add("connection.driver_class",
> > "NHibernate.Driver.SQLite20Driver");
> > properties.Add("connection.connection_string", @"Data
> > Source=D:\Projects\privat\WexioBridgen\src\Client\App_Data\wexiobridgen.db"
> > );
>
> > var fluentConfig = Fluently.Configure()
> > .Database(SQLiteConfiguration.Standard.UsingFile(
> > PathToSqlLiteDb))
> > .Mappings(m => m.FluentMappings
> > .Add<ClubMap>()
> > .Add<ScheduleMap>()
> > .Add<PersonMap>()
> > .Add<ContactTypeMap>()
> > .Add<ConventionRestrictionMap>()
> > .Add<TournamentTypeMap>()
> > .Add<TournamentMap>()
> > .Add<ResultTypeMap>()
> > .Add<ResultMap>()
> > .Add<NewsMap>())
> > .ExposeConfiguration(BuildSchema);
>
> > *var nhConfig = fluentConfig.BuildConfiguration().
> > SetProperties(properties);*
> > _sessionFactory = nhConfig.BuildSessionFactory();
> > _session = _sessionFactory.OpenSession();
>
> > 2009/7/21 Ben Hyrman <[email protected]>
>
> >> To double-check, you did copy NHibernate.ByteCode.Castle.dll to your bin,
> >> right?
>
> >> On Tue, Jul 21, 2009 at 1:18 PM, Brian Sullivan<[email protected]>
> >> wrote:
>
> >> > Thanks for the replies, guys!
>
> >> > James: I will try to create a failing test and get back to you. I
> >> > didn't realize that FNH defaulted to the Castle proxy factory
> >> > factory. Good to know, and a reasonable default, I think.
>
> >> > Ben: I remember having this same problem working with the beta, so I
> >> > doubt it's that. I decided to stick with 2.0.1 until it went GA to
> >> > see if the problem went away, either by changes in FNH or NH itself.
>
> >> > On Jul 21, 12:44 pm, Ben Hyrman <[email protected]> wrote:
> >> >> Here's one that is working fine for me against 2.1 beta (haven't gone
> >> >> to GA yet). I don't quite see where we differ.... I can go to 2.1GA
> >> >> and see if I run into your issue
>
> >> >> var fluentConfig = Fluently.Configure()
> >> >> .Database(MsSqlConfiguration.MsSql2005
> >> >> .ConnectionString(c => c
> >> >> .Is("Data Source=........"))
>
> >> >> .ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory,
> >> >> NHibernate.ByteCode.LinFu")
> >> >> .Cache(c =>
> >> >> c.ProviderClass("NHibernate.Caches.SysCache.SysCacheProvider,
> >> >> NHibernate.Caches.SysCache"))
> >> >> .UseReflectionOptimizer()
> >> >> .DoNot.ShowSql())
> >> >> .Mappings(m =>
> >> >> {
> >> >> m.HbmMappings.AddFromAssemblyOf<IEntity>();
> >> >> m.FluentMappings.AddFromAssemblyOf<IEntity>();
> >> >> });
>
> >> >> On Tue, Jul 21, 2009 at 12:14 PM, James Gregory<
> >> [email protected]> wrote:
> >> >> > Strange. It's not a requirement, FNH defaults to using Castle for the
> >> proxy
> >> >> > factory factory; however, you should still be able to specify it
> >> manually.
> >> >> > Can you create a failing test?
>
> >> >> > On Tue, Jul 21, 2009 at 5:37 PM, Brian Sullivan <
> >> [email protected]>
> >> >> > wrote:
>
> >> >> >> I'm trying to convert an application I've written using FNH and
> >> >> >> NH2.0.1GA to use the new 2.1GA libraries, but I'm running into a
> >> snag
> >> >> >> trying to specify my proxy factory factory. My configuration looks
> >> >> >> like this:
>
> >> >> >> SessionFactory =
> >> >> >> Fluently.Configure()
> >> >> >> .Database(
> >> >> >> MsSqlConfiguration.MsSql2005
> >> >> >> .ConnectionString(
> >> >> >> c => c.Is
> >> >> >> (ConfigurationManager.ConnectionStrings
> >> >> >> ["josubscriptioncb"].ConnectionString))
> >> >> >> .ProxyFactoryFactory
> >> >> >> ("NHibernate.ByteCode.Castle.ProxyFactoryFactory,
> >> >> >> NHibernate.ByteCode.Castle")
> >> >> >> )
> >> >> >> .Mappings(m =>
>
> >> >> >> m.FluentMappings.AddFromAssemblyOf<Campaign>()
>
> >> >> >> .ConventionDiscovery.AddFromAssemblyOf<Campaign>
> >> >> >> ())
> >> >> >> .BuildConfiguration().SetProperties(new
> >> >> >> Dictionary<string, string>()
> >> >> >> {
>
> >> >> >> {"current_session_context_class", "web"}
> >> >> >> })
> >> >> >> .BuildSessionFactory();
>
> >> >> >> When I run the web app, I get the following exception:
>
> >> >> >> The ProxyFactoryFactory was not configured.
> >> >> >> Initialize 'proxyfactory.factory_class' property of the session-
> >> >> >> factory configuration section with one of the available
> >> >> >> NHibernate.ByteCode providers.
> >> >> >> Example:
> >> >> >> <property
>
> >> name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFac
> >> tory,
> >> >> >> NHibernate.ByteCode.LinFu</property>
> >> >> >> Example:
> >> >> >> <property
>
> >> name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFa
> >> ctory,
> >> >> >> NHibernate.ByteCode.Castle</property>
>
> >> >> >> I then tried to set the property myself using SetProperties like
> >> this:
>
> >> >> >> .BuildConfiguration().SetProperties(new Dictionary<string, string>()
> >> >> >> {
>
> >> >> >> {"current_session_context_class", "web"},
>
> >> >> >> {"proxyfactory.factory_class",
> >> >> >> "NHibernate.ByteCode.Castle.ProxyFactoryFactory,
> >> >> >> NHibernate.ByteCode.Castle"}
> >> >> >> })
>
> >> >> >> When I do that, though, I get a different exception:
>
> >> >> >> Could not find the dialect in the configuration
>
> >> >> >> What is the correct way to configure the proxy factory factory in
> >> >> >> FNH? Also, should the examples on the wiki on fluentnhibernate.org
> >> >> >> be updated to reflect this new configuration requirement? Thanks in
> >> >> >> advance for any help you all can provide.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---