Reputation: 5122
This is my domain class:
public class User
{
public Guid id { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string mailAddress { get; set; }
}
This is my mapping file:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Test" namespace="Test.model">
<class name="User" >
<id name="id">
<generator class="guid"/>
</id>
<property name="firstName" />
<property name="lastName" />
<property name="mailAddress" />
</class>
</hibernate-mapping>
This is My hibernate-cfg file:
<?xml version="1.0" encoding="utf-8" ?>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">Server=localhost;Database=vbook;User ID=root;Password=ziben</property>
<!--<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>-->
<property name="hbm2ddl.auto">update</property>
<property name="generate_statistics">true</property>
<property name="show_sql">true</property>
<mapping file="data/mapping/User.hbm.xml" />
This is how I create session factory:
var configuration = new Configuration();
configuration.Configure();
_sessionFactory = configuration.BuildSessionFactory();
I get the following exception: Could not compile the mapping document: data/mapping/User.hbm.xml
I can't understand why.
Help please.
Upvotes: 0
Views: 334
Reputation: 123861
Any C# property of your entiy must be declared as virtual. Change your class this way:
public class User
{
public virtual Guid id { get; set; }
public virtual string firstName { get; set; }
public virtual string lastName { get; set; }
public virtual string mailAddress { get; set; }
}
Upvotes: 1