Hibernate version: 1.2.0.4000
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="DataAccessBase.DataAccess.Entities" assembly="DataAccessBase">
<class name="Users" table="Users">
<id name="Id" column="ID" type="Guid">
<generator class="assigned"/>
</id>
<property column="Username" type="String" name="Username" not-null="true" length="50" />
<property column="Password" type="String" name="Password" not-null="true" length="50" />
<property column="Email" type="String" name="Email" not-null="true" length="150" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Code:
System.TypeInitializationException was unhandled
Message="The type initializer for 'DataAccessBase.BaseDAO`1' threw an exception."
Source="DataAccessBase"
TypeName="DataAccessBase.BaseDAO`1"
StackTrace:
at DataAccessBase.BaseDAO`1.Save(Object item) in C:\Users\Hybrid\Documents\Visual Studio 2008\Projects\GFN\DataAccessBase\DataAccessBase\BaseDAO.cs:line 188
at DataAccessBase.DataAccess.DAO.UserDAO.CreateUser(String username, String password, String email) in C:\Users\Hybrid\Documents\Visual Studio 2008\Projects\GFN\DataAccessBase\DataAccessBase\DataAccess\DAO\UserDAO.cs:line 15
at DataAccessBase.GFNBal.CreateUser(String username, String password, String email) in C:\Users\Hybrid\Documents\Visual Studio 2008\Projects\GFN\DataAccessBase\DataAccessBase\GFNBal.cs:line 9
at GFNTester.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Hybrid\Documents\Visual Studio 2008\Projects\GFN\GFNData\GFNTester\Form1.cs:line 17
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at GFNTester.Program.Main() in C:\Users\Hybrid\Documents\Visual Studio 2008\Projects\GFN\GFNData\GFNTester\Program.cs:line 16
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: NHibernate.MappingException
Message="Could not compile the mapping document: DataAccessBase.DataAccess.Mappings.Users.hbm.xml"
Source="NHibernate"
StackTrace:
at NHibernate.Cfg.Configuration.LogAndThrow(MappingException me)
at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc, String name)
at NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader, String name)
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
at NHibernate.Cfg.Configuration.AddResources(Assembly assembly, IList resources, Boolean skipOrdering)
at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly, Boolean skipOrdering)
at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
at DataAccessBase.BaseDAO`1.DAConfig..ctor() in C:\Users\Hybrid\Documents\Visual Studio 2008\Projects\GFN\DataAccessBase\DataAccessBase\BaseDAO.cs:line 84
at DataAccessBase.BaseDAO`1..cctor() in C:\Users\Hybrid\Documents\Visual Studio 2008\Projects\GFN\DataAccessBase\DataAccessBase\BaseDAO.cs:line 29
InnerException: NHibernate.HibernateException
Message="The dialect was not set. Set the property hibernate.dialect."
Source="NHibernate"
StackTrace:
at NHibernate.Dialect.Dialect.GetDialect()
at NHibernate.Dialect.Dialect.GetDialect(IDictionary props)
at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc, String name)
InnerException:
Hey fellas, I am having a problem that is about to drive me crazy. I have a windows form project and a class library. The class library contains all of my mappings and entities. The windows form project calls that DLL to get and set data.
Here is how the DLL is setup to load the nhibernate configuration:
Code:
DAConfig.AddAssembly(Assembly.GetExecutingAssembly());
sessionFactory =
DAConfig.Configure(Assembly.GetExecutingAssembly(), "DataAccessBase.nhibernate.cfg.xml").BuildSessionFactory();
session = sessionFactory.OpenSession();
The problem is that in the Windows Form project, this setup only works if my app.config looks like the following:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<nhibernate>
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect"/>
</nhibernate>
</configuration>
With the App.Config how it looks above, my application runs just fine. As soon as I take out that "dialect" key, you get the exceptions I listed above. What the hell is going on? Here is my NHibernate.cfg.xml:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string">(yeah right)</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="cache.use_query_cache">false</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="default_schema">dbo</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>