BuldSessionFactory() exception

72 views
Skip to first unread message

mynkow

unread,
Sep 8, 2011, 10:14:38 AM9/8/11
to nhu...@googlegroups.com
I am using NHibernate in Web Application. The first time I run on IIS 7 my webApp everything is OK. The second time I run it I get this: An item with the same key has already been added. Any idea what I am doing wrong?
 
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at NHibernate.Util.ThreadSafeDictionary`2.Add(TKey key, TValue value) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Util\ThreadSafeDictionary.cs:line 44
   at NHibernate.Type.TypeFactory.GetType(NullableType defaultUnqualifiedType, Int32 length, GetNullableTypeWithLength ctorDelegate) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Type\TypeFactory.cs:line 611
   at NHibernate.Type.TypeFactory.BuiltInType(String typeName, Int32 length) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Type\TypeFactory.cs:line 392
   at NHibernate.Mapping.SimpleValue.GetHeuristicType() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\SimpleValue.cs:line 259
   at NHibernate.Mapping.SimpleValue.get_Type() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\SimpleValue.cs:line 231
   at NHibernate.Mapping.SimpleValue.IsValid(IMapping mapping) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\SimpleValue.cs:line 327
   at NHibernate.Mapping.PersistentClass.Validate(IMapping mapping) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\PersistentClass.cs:line 950
   at NHibernate.Mapping.RootClass.Validate(IMapping mapping) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\RootClass.cs:line 372
   at NHibernate.Cfg.Configuration.ValidateEntities() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1021
   at NHibernate.Cfg.Configuration.BuildSessionFactory() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1238

mynkow

unread,
Sep 8, 2011, 10:31:27 AM9/8/11
to nhu...@googlegroups.com
I am using NHiberante 3.1

Jason Meckley

unread,
Sep 8, 2011, 10:39:34 AM9/8/11
to nhu...@googlegroups.com
you'll need to provide some code so we can see what's going on and where this is happening.

mynkow

unread,
Sep 8, 2011, 10:57:19 AM9/8/11
to nhu...@googlegroups.com
I am calling BuildSessionFactory() method of the Configuration object. I suspect that for some reason The SessionFactory is already built...

Richard Wilde

unread,
Sep 8, 2011, 10:56:50 AM9/8/11
to nhu...@googlegroups.com

Make sure you are only calling BuildSessionFactory() ONCE on application startup!

Rippo

 

From: nhu...@googlegroups.com [mailto:nhu...@googlegroups.com] On Behalf Of mynkow
Sent: 08 September 2011 15:31
To: nhu...@googlegroups.com
Subject: [nhusers] Re: BuldSessionFactory() exception

 

I am using NHiberante 3.1

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/72J6bldz2mgJ.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

mynkow

unread,
Sep 9, 2011, 5:12:33 AM9/9/11
to nhu...@googlegroups.com
The code is correct. The problem is the workflow. I will try to explain how the things work in my web application.

1) I have a singleton class SessionFactoryProvider which reads nhibernate configuration and builds a session factory (SF). When the SF is built I put it in a field so SessionFactoryProvider can return it for later use.
2) When the application starts (global.asax/Application_Start) the SessionFactoryProvider builds SF and stores it in the HttpApplication[somekey].
3) For session management I use HttpModule to open ISession and close session at Begin/End request.
       - Get the SessionFactoryProvider from HttpApplication[somekey];
       - Get the current SF
       - SF.OpenSession
4) On Application_End the SF is closed.

So far so good. This workflow will always work if 2 and 4 are always called. Here is the tricky part. When I start debugging I can click Stop which will cause to skipp step 4. ResetIIS and start the application again will try to create a new SessionFactory but the previous one is not closed.

Q1) Does nhibernate stores somewhere an information statically about the active SFs?
Q2) Is there any way to get all Active SFs or kill them?
Reply all
Reply to author
Forward
0 new messages