Thursday, November 3, 2011

NHibernate.MappingException: No persister for Fluent

if you get this in Jcdc

NHibernate.MappingException: No persister for

First check to be sure your EO And MAP are both public.
Also look for a spelling error in you MAP file
Verify the namespaces are correct.
Make sure you have 1 Eo to each EOMap

If your EO is in JcdcHelper, or some other assembly here is the issue

jcdcFactory.BuildFactoryByConfigFile( "~/JcdcDb.config" );

ONLY loads from the assembly of Student EO and EOMAP which is ususally YOUR apps assembly.

Here are the guts

public void BuildFactoryByConfigFile(string rawFilePathToGetMapPath)
{
// Build local fluentConfig
NHibernate.Cfg.Configuration localConfiguration = new NHibernate.Cfg.Configuration();
localConfiguration = localConfiguration.Configure(GetMapPath(rawFilePathToGetMapPath));
FluentConfiguration localFluent = Fluently.Configure(localConfiguration);
localFluent.Mappings(
m =>
{
// this step scans your assembly for EO and maps in Cis3G
// you would have to add two more lines to scan
// your JCDCHelper EO and Maps

m.HbmMappings.AddFromAssemblyOf();
m.FluentMappings.AddFromAssemblyOf()
.AddFromAssemblyOf();
}
)
.ExposeConfiguration(
cfg =>
{
cfg.SetListener(ListenerType.PreInsert, new AuditEventListener());
cfg.SetListener(ListenerType.PreUpdate, new AuditEventListener());
}
);
// build session from FluentConfiguration
localFactory = localFluent.BuildSessionFactory();

}


As you can see you woudl need to make your own copy and modify
these lines

m.HbmMappings.AddFromAssemblyOf();
m.FluentMappings.AddFromAssemblyOf()
.AddFromAssemblyOf();


to call from JcdcHelper.EO and .EOMap as well, (or whatever assembly you are using)