I'm using v2.1 of NHibernate.dll and NHibernate.Mappings.Attributes v2.1 in a project.
When I run the code further below, I get the following exception, and will be grateful for any pointers. On the same project, if I remove the attributes and use xml mapping files, it works fine.
NHibernate.MappingException was unhandled
Message="Could not compile the mapping document:
DomainModel.hbm.xml"
Source="NHibernate"
InnerException: System.NullReferenceException
Message="Object reference not set to an instance of an object."
Source="NHibernate"
StackTrace:
at NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindClass
(XmlNode node, PersistentClass model)
at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind
(XmlNode node, HbmClass classSchema)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode
parentNode)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node)
at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
InnerException:
I have a contact class as follows (Domain class has just one method, no properties):
[NHibernate.Mapping.Attributes.Class]
public class Contact : DomainClass
{
[NHibernate.Mapping.Attributes.Id(Name = "Id")]
[NHibernate.Mapping.Attributes.Generator(1, Class ="Identity")]
public virtual int ID { get; set; }
[NHibernate.Mapping.Attributes.Property]
public virtual string Name { get; set; }
[NHibernate.Mapping.Attributes.Property]
public virtual string Town { get; set; }
}
and session code as follows:
Configuration cfg = new Configuration();
cfg.Configure();
cfg.AddInputStream(NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(
typeof(Contact).Assembly), "DomainModel.hbm.xml");
_sessionFactory=cfg.BuildSessionFactory();
My hibernate.cfg.xml file is:
<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=SERVER
\EXPRESS2008;Initial Catalog=Contacts;Integrated Security=True</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFac tory, NHibernate.ByteCode.LinFu</property>
</session-factory>
</hibernate-configuration>