Problem: I have been teaching myself nHibernate using some existing discussion/examples from
http://www.codeproject.com/script/profile/add_bookmark.asp?t=0&ct=%2Faspnet%2FNHibernateBestPractices%2Easp&guid=NHibernateBestPractices%2Faspnet3%2F12%2F2006.
The basic sample compiles and builds on my machine. Taking the basic sample as a template, I've created my own project. The only real difference is that my domain objects are fewer and simpler (only one with a handful of regular properties).
In both unit testing and in compiling the application, I get an error (see further below) that states "<session-factory> element was not found in the configuration file". If you look at my App.config contents below (used in the GSConcept2.Tests project), the <session-factory> element does indeed exist. I also get the same error when running the application, but the GSConcept2.Web project obviously has it's own web.config. It looks the same, though.
So, trying to debug doesn't show me much. NUnit fails on this method:
Code:
[Test]
public void TestGetById()
{
IDaoFactory daoFactory = new NHibernateDaoFactory();
IAthleteDao athleteDao = daoFactory.GetAthleteDao();
Athlete foundAthlete = athleteDao.GetById(Globals.TestAthlete.Id, false);
Assert.AreEqual(Globals.TestAthlete.FullName, foundAthlete.FullName);
}
I'm a bit lost as to where else to look. I'm hoping someone else has seen this issue and it's a simple change...
Any advice is appreciated.
Hibernate version: Project comes up as 1.1, but zip file titled 1.0.4.0.
Mapping documents: HBM (as embedded resource):
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="GSConcept2.Core.Domain.Athlete, GSConcept2.Core" table="Athletes" lazy="false">
<id name="id" access="field" column="Id">
<generator class="native" />
</id>
<property name="FirstName" column="FirstName" />
<property name="LastName" column="LastName" />
<property name="Birthdate" column="Birthdate" />
</class>
</hibernate-mapping>
-------------------------------
App.config
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=(local);Database=NickTest1;Integrated Security=SSPI;</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="default_schema">NickTest1.dbo</property>
<!-- HBM Mapping Files -->
<mapping assembly="GSConcept2.Core" />
</session-factory>
</hibernate-configuration>
</configuration>
Full stack trace of any exception that occurs:Code:
GSConcept2.Tests.Data.AthleteDaoTests (TestFixtureSetUp) : System.TypeInitializationException : The type initializer for 'Nested' threw an exception.
----> NHibernate.MappingException : <session-factory> element was not found in the configuration file.
at GSConcept2.Data.NHibernateSessionManager.get_Instance() in C:\Documents and Settings\nkirkes\My Documents\Visual Studio 2005\Projects\GSConcept2\GSConcept2.Data\NHibernateSessionManager.cs:line 27
at GSConcept2.Tests.Data.NHibernateTestCase.Setup() in C:\Documents and Settings\nkirkes\My Documents\Visual Studio 2005\Projects\GSConcept2\GSConcept2.Tests\Data\NHibernateTestCase.cs:line 14
--MappingException
at NHibernate.Cfg.Configuration.DoConfigure(XmlDocument doc)
at NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)
at NHibernate.Cfg.Configuration.Configure(XmlNode node)
at NHibernate.Cfg.Configuration.Configure()
at GSConcept2.Data.NHibernateSessionManager.InitSessionFactory() in C:\Documents and Settings\nkirkes\My Documents\Visual Studio 2005\Projects\GSConcept2\GSConcept2.Data\NHibernateSessionManager.cs:line 53
at GSConcept2.Data.NHibernateSessionManager..ctor() in C:\Documents and Settings\nkirkes\My Documents\Visual Studio 2005\Projects\GSConcept2\GSConcept2.Data\NHibernateSessionManager.cs:line 36
at GSConcept2.Data.NHibernateSessionManager.Nested..cctor() in C:\Documents and Settings\nkirkes\My Documents\Visual Studio 2005\Projects\GSConcept2\GSConcept2.Data\NHibernateSessionManager.cs:line 45
Name and version of the database you are using:
Sql Server 2005
DB Name: NickTest1