I'm trying to achieve simple mapping using mapping.attributes. Somehow, it doesn't work. My Decorated Class is in the same namespace as the program, configuration is done via xml-file.
Although i use the Mappings.Attributes, I always get a "resource not found
QuickStart.User.hbm.xml" Exception.
Here's all I have done so far:
Code:
/*program.cs*/
namespace QuickStart
{
class Program
{
static void Main(string[] args)
{
try
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true;
cfg.AddInputStream( NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize( System.Reflection.Assembly.GetExecutingAssembly()
)
);
cfg.AddClass(typeof(User));
cfg.Configure("C:\\path\\nhibernate.config");
ISessionFactory sf = cfg.BuildSessionFactory();
ISession ses = sf.OpenSession();
ITransaction ta = ses.BeginTransaction();
ses.Close();
}
catch (Exception e)
{
Console.Out.WriteLine(e.Message);
}
}
}
}
Code:
<!--xmlconfig-->
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">Data Source=srv.foo.de; User Id=usrid; Password=pwd; Persist Security Info=True;</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="query.substitutions">True=1;False=0</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
Code:
/*mapped filed*/
namespace QuickStart
{
[NHibernate.Mapping.Attributes.Class(0,
Table = "users",
Schema = "schema")]
public class User
{
[NHibernate.Mapping.Attributes.Id(0,
Column = "logonid",
Name = "logonId",
TypeType = typeof(string),
UnsavedValue = "")]
public string logonId;
[NHibernate.Mapping.Attributes.Property(0,
Column = "name",
Name = "Name",
TypeType = typeof(string),
NotNull = true,
Length = 100)]
public string name;
}
}
Full stack trace of any exception that occurs:
bei NHibernate.Cfg.Configuration.LogAndThrow(MappingException me)
bei NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
bei NHibernate.Cfg.Configuration.AddClass(Type persistentClass)
bei QuickStart.Program.Main(String[] args) in C:\path\HibernateTest\Program.cs:Zeile 27.
Name and version of the database you are using:
oracle10g
Can anyone help me on this?