[BuildSessionFactory] Creating new instances of objects?

26 views
Skip to first unread message

Michael Powell

unread,
Feb 11, 2016, 9:44:15 AM2/11/16
to fluent-n...@googlegroups.com
Hello,

I am curious, I have a stack trace that indicates building a session
factory is actually creating new instances of my mapped (?) domain
model?

Is that accurate? If so, why? What's wrong with doing a little
reflection followed closely by throwing an exception, or even, if
possible, using the "new()" generic constraint?

I kind of expect a handshake of sorts between any data layer and the
underlying model, but I'm not sure this is the right time and/or way
to find it out.

> Football.dll!Football.Models.GameSituation.Initialize() Line 927 C#
Football.dll!Football.Models.GameSituation.GameSituation() Line 905
+ 0x9 bytes C#
[External Code]
FluentNHibernate.dll!FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
Line 230 + 0x18 bytes C#
Football.Data.dll!Football.Data.Repository.Hibernate.NHibernateSessionFactoryManagerBase.CreateFactory()
Line 131 + 0xb bytes C#
Kingdom.Repository.dll!Kingdom.Repository.SessionFactoryManagerBase<NHibernate.ISessionFactory>.Factory.get()
Line 37 + 0x1a bytes C#
Football.Migrator.exe!Football.Migrator.Program.PlanWork(System.Action<Kingdom.Repository.IRepository>
workPlan) Line 39 + 0xe bytes C#
Football.Migrator.exe!Football.Migrator.Program.Main(string[] args)
Line 66 + 0x36 bytes C#
[External Code]

Suggestions?

Thank you.

Regards,

Michael Powell

Gleb Chermennov

unread,
Feb 12, 2016, 5:19:04 AM2/12/16
to Fluent NHibernate
Hello Michael, 
as far as I know, creating a session factory shouldn't instantiate any of your domain objects.
May be you can share your code here or in an email?

четверг, 11 февраля 2016 г., 17:44:15 UTC+3 пользователь mwpowellhtx написал:

mwpowellhtx

unread,
Feb 13, 2016, 11:14:26 AM2/13/16
to Fluent NHibernate


On Friday, February 12, 2016 at 5:19:04 AM UTC-5, Gleb Chermennov wrote:
Hello Michael, 
as far as I know, creating a session factory shouldn't instantiate any of your domain objects.
May be you can share your code here or in an email?

I've got a stack trace that says new instances are being created. If not Fluent/NHibernate code, then the proxy instance DLL creation?

> Football.dll!Football.Models.GameSituation.GameSituation() Line 905 C#

mwpowellhtx

unread,
Feb 13, 2016, 11:30:24 AM2/13/16
to Fluent NHibernate


On Saturday, February 13, 2016 at 11:14:26 AM UTC-5, mwpowellhtx wrote:


On Friday, February 12, 2016 at 5:19:04 AM UTC-5, Gleb Chermennov wrote:
Hello Michael, 
as far as I know, creating a session factory shouldn't instantiate any of your domain objects.
May be you can share your code here or in an email?

Let's put it another way, when I put a unit test in your Fluent NHibernate that a test model's default ctor should not be invoked, literally call Assert.Fail() in the default ctor, then this should be sufficient to test that hypothesis?

mwpowellhtx

unread,
Feb 13, 2016, 11:38:58 AM2/13/16
to Fluent NHibernate


On Saturday, February 13, 2016 at 11:30:24 AM UTC-5, mwpowellhtx wrote:


On Saturday, February 13, 2016 at 11:14:26 AM UTC-5, mwpowellhtx wrote:


On Friday, February 12, 2016 at 5:19:04 AM UTC-5, Gleb Chermennov wrote:
Hello Michael, 
as far as I know, creating a session factory shouldn't instantiate any of your domain objects.
May be you can share your code here or in an email?

Let's put it another way, when I put a unit test in your Fluent NHibernate that a test model's default ctor should not be invoked, literally call Assert.Fail() in the default ctor, then this should be sufficient to test that hypothesis?

Best guess without diving much further, somewhere in the bowels of this NHibernate-Core monster:

/// <summary>
/// Instantiate a new <see cref="ISessionFactory" />, using the properties and mappings in this
/// configuration. The <see cref="ISessionFactory" /> will be immutable, so changes made to the
/// configuration after building the <see cref="ISessionFactory" /> will not affect it.
/// </summary>
/// <returns>An <see cref="ISessionFactory" /> instance.</returns>
public ISessionFactory BuildSessionFactory()
{
ConfigureProxyFactoryFactory();
SecondPassCompile();
Validate();
Environment.VerifyProperties(properties);
Settings settings = BuildSettings();

// Ok, don't need schemas anymore, so free them
Schemas = null;

return new SessionFactoryImpl(this, mapping, settings, GetInitializedEventListeners());
}

Gleb Chermennov

unread,
Feb 13, 2016, 1:41:20 PM2/13/16
to fluent-n...@googlegroups.com
I think the proxy suggestion is worth checking out.
About NHibernate itself - try asking on their mailing list.

--
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/HuIJ6gCc0gw/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 https://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/d/optout.



--
Yours faithfully, 
Gleb

mwpowellhtx

unread,
Feb 13, 2016, 1:52:38 PM2/13/16
to Fluent NHibernate


On Saturday, February 13, 2016 at 1:41:20 PM UTC-5, Gleb Chermennov wrote:
I think the proxy suggestion is worth checking out.

Thanks. This looks like the likely culprit.
 
About NHibernate itself - try asking on their mailing list.

Already on it. Appreciate the feedback. 
Reply all
Reply to author
Forward
0 new messages