Hi everyone, I've got a problem when I tried to map the hbm.xml file with the .cs file. When I launch the program I've got a MappingException:
Resource not found: Cat.hbm.xml
I can't figure out why it doesn't work with my code.
If someone can help me, I'll be grateful :D
Thanks.
Hibernate version: 1.2.0
Files:
App.conf
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.connection_string">
Server=(localhost);initial catalog=Quickstart;Integrated Security=SSI
</property>
<mapping assembly="Quickstart" />
<mapping resource="Cat.hbm.xml" assembly="Quickstart" />
</session-factory>
</hibernate-configuration>
</configuration>
Cat.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Quickstart" assembly="Quickstart">
<class name="Cat" table="Cat">
<id name="Id" column="CatId" type="Char" length="32">
<generator class="assigned" />
</id>
<property name="Name" column="Name" type="String" length="40" not-null="true" />
<property name="Sex" column="Sex" type="Char" length="1" not-null="false"/>
</class>
</hibernate-mapping>
Cat.cs
Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace Quickstart
{
public class Cat
{
private string id;
private string name;
private char sex;
public Cat()
{
}
public string Id
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public char Sex
{
get { return sex; }
set { sex = value; }
}
}
}
Program.cs
Code:
Configuration cfg = new Configuration();
cfg.Configure(); // <-- Crash here
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
...
Full stack trace of any exception that occurs:
" at NHibernate.Cfg.Configuration.LogAndThrow(MappingException me)\r\n at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)\r\n at NHibernate.Cfg.Configuration.DoConfigure(XmlDocument doc)\r\n at NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)\r\n at NHibernate.Cfg.Configuration.Configure(XmlNode node)\r\n at NHibernate.Cfg.Configuration.Configure()\r\n at Quickstart.Program.Main(String[] args) in C:\\Documents and Settings\\dde\\My Documents\\Visual Studio 2005\\Projects\\Quickstart\\Quickstart\\Program.cs:line 18\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"